Game Development Reference
In-Depth Information
What we want to do now is to combine all of this code to implement a seemingly simple thing:
create an application that renders a textured quad and updates its texture on-the-ly. An
application starts, a white quad appears on the screen, and then, as soon as the texture ile
has loaded from disk, the quad's texture changes. This is relatively easy to do—we just run
the LoadImage task that we implement here, and as soon as this task completes, we get the
completion event on the main thread, which also owns an event queue. We cannot get away
with a single mutex to update the texture data, because when we use the OpenGL texture
objects in Chapter 6 , Unifying OpenGL ES 3 and OpenGL 3, all of the rendering state must be
changed only in the same thread that created the texture—in our main thread.
Getting ready
We strongly encourage you to review all of the multithreading techniques from Chapter 3 ,
Networking . The simple rendering techniques we use here are covered in the in the App3
example in Chapter 1, Establishing a Build Environment, and in the App4 example in
Chapter 2, Porting Common Libraries.
How to do it...
1.
Here we build the foundation for the resources management. We need the concept of
a bitmap stored in a memory. It is implemented in the Bitmap class, as shown in the
following code:
class Bitmap: public iObject
{
public:
Bitmap( const int W, const int H)
{
size_t Size = W * H * 3;
if ( !Size ) { return; }
FWidth = W;
FHeight = H;
FBitmapData = (ubyte*)malloc( Size );
memset(FBitmapData, 0xFF, Size);
}
virtual ~Bitmap() { free(FBitmapData); }
void Load2DImage( clPtr<iIStream> Stream )
{
free( FBitmapData );
FBitmapData = read_bmp_mem(
Stream->MapStream(), &FWidth, &FHeight );
}
 
Search WWH ::




Custom Search