Sign in to follow this  
Imaginate

OpenGL Texture Loading

Recommended Posts

Hi there, I'm developing a 2D Game Engine, which is currently using GDI to draw, but I want to use OpenGL. So far, I've been sucessful in drawing shapes to the screen ( by adding code to my engine's GDI-based functions that replaces GDI calls with OpenGL calls ), and I've come to the point where I need to precache an image. I know how to precache images as textures, but the thing is, the images aren't always precached at once. The GDI version simply retrieves an HBITMAP and places it within a vector, so it can be drawn by giving a supplied handle. However, if I'm not mistaken, OpenGL wants me to precache all textures at once, after calling glGenTextures or something of the sort. I can't do this, as it would destroy the engine's functionality. The current GDI function loads in the image to an IPicture, then into a DDB HBITMAP, which is stored in a vector, and then the drawing function cross-references the handle with another vector of handles, which allows the drawing function to access the HBITMAP. Using OpenGL, how can I have the precaching function work without destroying already precached images ( since images can be precached at anytime by the client-game ) ? Thanks, The Imaginate

Share this post


Link to post
Share on other sites
Quote:
Original post by Imaginate
...
However, if I'm not mistaken, OpenGL wants me to precache all textures at once, after calling glGenTextures or something of the sort.
...
You are mistaken. OpenGL has no such restriction on when you create textures; as long as there is a current valid rendering context you can create a texture pretty much whenever you want.

Share this post


Link to post
Share on other sites
GLuint textura[1];

AUX_RGBImageRec *LoadBMP(char *nomFitxer) {
FILE *File = NULL;
if (!nomFitxer) {
return NULL;
}
File=fopen(nomFitxer,"r");
if (File) {
fclose(File);
return auxDIBImageLoad(nomFitxer);
}
return NULL;
}

int LoadGLTextures() {
int Status = FALSE;
AUX_RGBImageRec *TextureImage[1];
memset(TextureImage, 0, sizeof(void *)*1);
if (TextureImage[0]=LoadBMP("pathFile")) {
Status = TRUE;
glGenTextures(1, &textura[0]);
glBindTexture(GL_TEXTURE_2D, textura[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

}
if (TextureImage[0]) {
if (TextureImage[0]->data) {
free(TextureImage[0]->data);
}
}
return Status;
}


I Hope this can help you.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this