I have been struggling for quite some time in learning(and understanding) how to load a bitmap in OpenGL (Just get it on the screen)
I’m getting really confused in all the “red tape” involved so I thought somebody could answer these questions:
1-Does OpenGl have support for loading bitmaps? or is this a Windows only thing(embedded in an Opengl program)
2- Every tutorial I see on the net about this uses glaux. Why? I never see tutorials(of any kind)using glutCreateWindow().
3-Do I really have to study windows programming to understand how loading the bitmap works?
I don’t want to copy/use anyone else’s code to do this. I want to understand (by looking at someone’s code) and then write the code myself. So far every tutorial I look at (this one is from NeHe) goes something like this:
HDC hDC=NULL;
HGLRC hRC=NULL;
HWND hWnd=NULL;
HINSTANCE hInstance
bool keys[256];
bool active=TRUE;
bool fullscreen=TRUE;
GLfloat xrot;
GLfloat yrot;
GLfloat zrot;
GLuint texture[1];
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
AUX_RGBImageRec *LoadBMP(char *Filename
{
FILE *File=NULL;
if (!Filename)
{
return NULL;
}
File=fopen(Filename,"r");
if (File)
{
fclose(File);
return auxDIBImageLoad(Filename);
}
return NULL;
}
int LoadGLTextures()
{
int Status=FALSE;
AUX_RGBImageRec *TextureImage[1];
memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL
// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
if (TextureImage[0]=LoadBMP("Data/NeHe.bmp"))
{
Status=TRUE; // Set The Status To TRUE
glGenTextures(1, &texture[0]); // Create The Texture
// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}
if (TextureImage[0]) // If Texture Exists
{
if (TextureImage[0]->data) // If Texture Image Exists
{
free(TextureImage[0]->data); // Free The Texture Image Memory
}
free(TextureImage[0]); // Free The Image Structure
}
return Status; // Return The Status
}
5-Does it really have to be this complicated? I am not an advanced OpenGl/C programmer but this code makes zero sense to me…I’m guessing I can’t just call some function with the name of my file and load it into memory…then call another function to display it…Is any of the above code OpenGl at all? Or is all that Windows95/98 stuff…
Any clarification would be great…Thanks so much…