2D Panels

Hi,

With my OpenGL application how can I load images from the applications resource file and then display them on the screen with OpenGL.

Another smaller question is how can I draw with the standard GDI in conjunction with OpenGL to remove the flicker.

Any help would be greatly appreciated!

Yours Sincerely,
Lea Hayes

I recall one of Nehe’s tutorials at nehe.gamedev.net showing how to use MSVCs resource files for textures. So you may want to check that out.

Can’t help with the other question though, sorry.

Tina

On the GDI, I think there is a way to do it.
I think you render to a bitmap, then display it with the GDI.
But if you are getting flicker, are you using double buffer in your draw routine?
Also maybe it is how you are drawing your scene. Would have to know more about how you build your scene.

Originally posted by leahayes00:
[b]Hi,

With my OpenGL application how can I load images from the applications resource file and then display them on the screen with OpenGL.

Another smaller question is how can I draw with the standard GDI in conjunction with OpenGL to remove the flicker.

Any help would be greatly appreciated!

Yours Sincerely,
Lea Hayes[/b]

For loading arbitrary binary resources, you basically do something like so…

HGLOBAL hResource = LoadResource(hModule, hResInfo);
void* pData = LockResource(hResource);

// Access the data for the resource from pData.

Sorry, dont have time to explaing it all right now but here is how I do it …

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Load a texture from a resource and return it’s index (0 on error); Setup
// the texture using the following default characteristics:
// Environment Mode = GL_MODULATE
// S Wrap Method = GL_REPEAT
// T Wrap Method = GL_REPEAT
// Magnification Filter=GL_LINEAR
// Minification Filter=GL_LINEAR_MIPMAP_LINEAR
// Perspective Correction Hint = GL_NICEST

size_t MgTextureManager::
loadTextureFromResource(
unsigned int resourceId,
const char* textureName,
bool mipMapped
)
{
if (!IsOpenGlInitialized())
{
m_LastErrorDescription =
“Attempted to load a texture prior to OpenGL Initialization”;
return 0;
}

// Load the image;
GLuint texIndx(0);
glGenTextures(1,&texIndx);
if (texIndx==0)
{
MgString msg(
"Failed generating texture OpenGL index for texture named ",
textureName
);
msg << “|” << GetOpenGLErrorMessage();
m_LastErrorDescription = msg;
return 0;
}

glBindTexture(GL_TEXTURE_2D,texIndx);
MgTextureOptions options;
options.apply();

HINSTANCE hInstance;
HANDLE hBitmap;
BITMAPINFO bmInfo;
void *pBitmapData;

// Find the bitmap resource
hInstance = GetModuleHandle(NULL);
hBitmap = LoadBitmap(hInstance,MAKEINTRESOURCE(resourceId));

if (hBitmap == NULL)
{
m_LastErrorDescription =
“Failed loading texture from bitmap resource”;
return 0;
}
GetObject(hBitmap,sizeof(BITMAPINFO),&bmInfo);
DeleteObject(hBitmap);

hBitmap =
LoadResource(
hInstance,
::FindResource(hInstance,MAKEINTRESOURCE(resourceId),RT_BITMAP)
);

if (hBitmap == NULL)
{
m_LastErrorDescription =
“Failed finding texture bitmap resource”;
return 0;
}

pBitmapData = LockResource(hBitmap);
int width = bmInfo.bmiHeader.biWidth;
int height = bmInfo.bmiHeader.biHeight;

// This is specific to the binary format of the data read in.
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);

if (mipMapped)
{
gluBuild2DMipmaps(
GL_TEXTURE_2D,
3,
width,
height,
GL_BGR_EXT,
GL_UNSIGNED_BYTE,
(unsigned char *)pBitmapData+sizeof(bmInfo)+2
);
}
else
{
glTexImage2D(
GL_TEXTURE_2D,
0,
3,
width,
height,
0,
GL_BGR_EXT,
GL_UNSIGNED_BYTE,
(unsigned char *)pBitmapData+sizeof(bmInfo)+2
);
}

TextureInfo info(texIndx,width,height,24);
info.options = options;
(*p_Textures)[MgStlString(textureName)] = info;

// Done with bitmap
DeleteObject(hBitmap);

return 0;
}

Hi,

Thanks for your help!

Yours Sincerely,
Lea Hayes