Skip to main content
GameDev.net gamedev.net
🔒 Locked

Can not Update texture-----help!

Started by lserlohn Jan 1, 2007 at 9:35 PM 4 replies 750+ views
Original Post
lserlohn
lserlohn
I created an openGL program, and want to update texture several times on the same surface when needed. So, first, I init openGL program and created one texture object and binded it,then loaded a bmp file and map on the surface, these all worked well. Later, I loaded another bmp file and tried to map it on the surface using the same texture object , but failed, the texture on the surface didn't change. I don't know why. Please help, I just a beginner. the code of load texture() function: //////////////////////////////////////////////////////////////////// bool LoadTexture(LPTSTR szFileName, GLuint &texid) // Creates Texture From A Bitmap File { HBITMAP hBMP; // Handle Of The Bitmap BITMAP BMP; // Bitmap Structure //glGenTextures(1, &texid); // Create The Texture hBMP=(HBITMAP)LoadImage(GetModuleHandle(NULL), szFileName, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE ); if (!hBMP) // Does The Bitmap Exist? return FALSE; // If Not Return False GetObject(hBMP, sizeof(BMP), &BMP); // Get The Object // hBMP: Handle To Graphics Object // sizeof(BMP): Size Of Buffer For Object Information // &BMP: Buffer For Object Information //glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // Pixel Storage Mode (Word Alignment / 4 Bytes) // Typical Texture Generation Using Data From The Bitmap glBindTexture(GL_TEXTURE_2D, texid); // Bind To The Texture ID glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Min Filter glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Mag Filter glTexImage2D(GL_TEXTURE_2D, 0, 3, BMP.bmWidth, BMP.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits); DeleteObject(hBMP); // Delete The Object return TRUE; // Loading Was Successful } ////////////////////////////////////////////////////////////////////////
GamerYZ
GamerYZ
Make sure you are not calling this function between glBegin and glEnd.
lserlohn
lserlohn
yes, I'm sure that. Is there any other wrong using place may cause this problem?
GamerYZ
GamerYZ
Try calling glDeleteTextures before loading the new one, if you are not doing that already. That's the only thing I can think of if the code worked for loading one texture like you said.

I suggest you use an array of IDs, and pre load all the textures you'll need. File IO is slow anyways, and you should probably avoid doing that in middle of rendering.
FReY
FReY
A few thoughts:

* Does the second texture you load have power-of-2 dimensions?
* Does the file actually load? Ie. it doesn't exit at the 'return FALSE' statement?
* Does your card support EXT_bgra? (quite likely because it's official OpenGL 1.2 IIRC) You can find out by examining the string returned by calling glGetString().
* Does it do anything differently if you load the 2nd texture first and the 1st texture second?
do unto others... and then run like hell.
lserlohn
lserlohn
Thanks all!

Finally , I find I excuted this function in another process.

Topic Locked

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

Sign in to reply to this topic.