10-11-2019, 06:09 AM
I haven't been posting recently, mainly because of other projects and time commitments. Life happens.
One thing that I've been doing recently though, is learning how to program in C++! Finally got over the learning hump that had been holding me back for so many years, and over the past few weeks I've been gobbling up basic C++ ravenously. Got everything from classes, extension, basic pointer and memory mapping, command-line build systems (cmake), arrays and their bizarre handling syntax, and some remedial OpenGL.
And as always, one of my favorite experiments when learning anything new is to embed Tilengine in it. It was actually even easier than usual, as Tilengine's C-nature makes it relatively painless to use it in conjunction with C++. (just include and link, and then you can call the C functions directly) For this one, I created a custom SDL window with an OpenGL context, and then mapped the output from Tilengine to a textured OpenGL quad. Here's the line of code that really makes the magic happen.
This is the OpenGL function that draws a pixel array to the currently bound OpenGL texture. Basically, you create a texture, create a pixel array, target Tilengine to the Pixel array, update your frame in Tilengine, bind your texture, call that line of code, and then draw your texture to a 3D element. (in this case a simple quad) That simple.
It took a little bit of experimenting to get the right settings for the draw function, but I had a head start on that thanks to my previous attempts. Now that I've got Tilengine mapped into OpenGL, I can run things like fragment shaders on Tilengine's output. That will open a few possibilities that didn't exist before.
One thing that I've been doing recently though, is learning how to program in C++! Finally got over the learning hump that had been holding me back for so many years, and over the past few weeks I've been gobbling up basic C++ ravenously. Got everything from classes, extension, basic pointer and memory mapping, command-line build systems (cmake), arrays and their bizarre handling syntax, and some remedial OpenGL.
And as always, one of my favorite experiments when learning anything new is to embed Tilengine in it. It was actually even easier than usual, as Tilengine's C-nature makes it relatively painless to use it in conjunction with C++. (just include and link, and then you can call the C functions directly) For this one, I created a custom SDL window with an OpenGL context, and then mapped the output from Tilengine to a textured OpenGL quad. Here's the line of code that really makes the magic happen.
Code:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, targetWidth, targetHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, pixelsPointer);
This is the OpenGL function that draws a pixel array to the currently bound OpenGL texture. Basically, you create a texture, create a pixel array, target Tilengine to the Pixel array, update your frame in Tilengine, bind your texture, call that line of code, and then draw your texture to a 3D element. (in this case a simple quad) That simple.
It took a little bit of experimenting to get the right settings for the draw function, but I had a head start on that thanks to my previous attempts. Now that I've got Tilengine mapped into OpenGL, I can run things like fragment shaders on Tilengine's output. That will open a few possibilities that didn't exist before.