Loading TGA files to openGL Textures
It still has the same problem. Does anything in tga.c need to be modified too?
For some strange reason it shows only the last texture loaded
For example if I do this:
This draws the most recent texture loaded (loading.tga), instead of the textyre specified (myTexture/opening.tga). Is there any obvious reason why?
For example if I do this:
PHP Code:
TextureImage myTexture;
TextureImage myTexture2;
LoadTGA(&myTexture, "/Data/GFX/opening.tga");
CreateTexture(&myTexture, 0);
LoadTGA(&myTexture, "/Data/GFX/loading.tga");
CreateTexture(&myTexture2, 0);
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
glColor4f(1.0,1.0,1.0,1.0);
glBindTexture(GL_TEXTURE_2D, myTexture.texID);
glTexCoord2f(0.0, 0.0);
glVertex2f( 0.0f, -128.0f);
glTexCoord2f(1.0, 0.0);
glVertex2f(1024.0f, -128.0f);
glTexCoord2f(1.0, 1.0);
glVertex2f(1024.0f, 896.0f);
glTexCoord2f(0.0, 1.0);
glVertex2f( 0.0f, 896.0f);
glEnd();
glDisable(GL_TEXTURE_2D);
This draws the most recent texture loaded (loading.tga), instead of the textyre specified (myTexture/opening.tga). Is there any obvious reason why?
Joseph Duchesne Wrote:This draws the most recent texture loaded (loading.tga), instead of the texture specified (myTexture/opening.tga). Is there any obvious reason why?Code:
TextureImage myTexture;
TextureImage myTexture2;
LoadTGA(&myTexture, "/Data/GFX/opening.tga");
CreateTexture(&myTexture, 0);
LoadTGA(&myTexture, "/Data/GFX/loading.tga");
CreateTexture(&myTexture2, 0);
Yeah, you want to change
LoadTGA(&myTexture, "/Data/GFX/loading.tga"); to
LoadTGA(&myTexture2, "/Data/GFX/loading.tga");
The way the tga loader works is it loads in the file into an image buffer (a large array of bytes in RGB or ARGB order). When you call CreateTexture, it uploads the data from that image buffer to OpenGL to make a texture from it. It stores an index to that texture in the TextureImage struct as well, so you need one unique TextureImage instance per image you want to use.
strangely, even when I changed it it still didn't work.
It shows the most recently loaded texture instead of the one I want. Has anyone else had similar problems?
Code:
TextureImage myTexture;
TextureImage myTexture2;
LoadTGA(&myTexture, "/Data/GFX/opening.tga");
CreateTexture(&myTexture, 0);
LoadTGA(&myTexture2, "/Data/GFX/loading.tga");
CreateTexture(&myTexture2, 0);
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
glColor4f(1.0,1.0,1.0,1.0);
glBindTexture(GL_TEXTURE_2D, myTexture.texID); //even if I delete this line it shows myTexture2, not 1.
glTexCoord2f(0.0, 0.0);It shows the most recently loaded texture instead of the one I want. Has anyone else had similar problems?
Joseph Duchesne Wrote:It shows the most recently loaded texture instead of the one I want. Has anyone else had similar problems?You can't use glBindTexture() within a glBegin()/glEnd() block. Move it to before glBegin().
Thanks, that wasn't in the manual
. (it [probably was, I just never saw it)
. (it [probably was, I just never saw it)
kberg (or anyone) what is the extension .cc? I'm used to .h, .c, .cpp, .hpp but not .cc.
man glBindTexture:
GL_INVALID_OPERATION is generated if glBindTexture is executed between
the execution of glBegin and the corresponding execution of glEnd.
glGetError() will catch all these sort of problems for you.
GL_INVALID_OPERATION is generated if glBindTexture is executed between
the execution of glBegin and the corresponding execution of glEnd.
glGetError() will catch all these sort of problems for you.
SimReality/Nick Wrote:kberg (or anyone) what is the extension .cc? I'm used to .h, .c, .cpp, .hpp but not .cc.It's just another C++ extension. I've also seen ".cp" and ".C" used for C++ (the latter obviously only works on case-sensitive filesystems!).
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| OpenAL - Ogg files vs Caf files | Fred9000 | 8 | 11,770 |
Aug 23, 2011 08:01 PM Last Post: ipeku |
|
| [SOLVED]OpenGL edges of textures | mk12 | 2 | 3,628 |
Sep 2, 2010 08:07 PM Last Post: mk12 |
|
| OpenGL ES Loading images | techy | 4 | 3,358 |
Dec 24, 2009 02:01 PM Last Post: techy |
|
| OpenGL Image Textures | mikey | 52 | 20,021 |
Jun 30, 2009 10:42 AM Last Post: AnotherJake |
|
| Dealing with inverted textures in OpenGL | johncmurphy | 7 | 5,861 |
Jun 15, 2009 08:11 AM Last Post: Skorche |
|

