Skip to main content
gamedev.net
🔒 Locked

Texture Loading

Started by Imaginate 1 reply 750+ views
Original Post
Imaginate
Imaginate
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
Kalidor
Kalidor
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.
falledAngel
falledAngel
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.
I spent most of my money on booze, women and cars. The rest I just wasted. George Best

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.