(Link to AcmlmWiki) Offline: thank ||bass
Register | Login
Views: 13,040,846
Main | Memberlist | Active users | Calendar | Chat | Online users
Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album
06-26-24 08:48 PM
0 users currently in Programming.
Acmlm's Board - I3 Archive - Programming - GRAAAH OpenGL 2D texturing problem New poll | |
Add to favorites | Next newer thread | Next older thread
User Post
Disch

Red Cheep-cheep


 





Since: 12-10-05

Last post: 6617 days
Last view: 6617 days
Posted on 01-30-06 03:44 PM Link | Quote
I'm going bonkers. I've looked at my previous OpenGL test programs (which all worked fine) to make sure I'm not missing a step here... but still, it's just not working. So I come here, in hopes that someone can tell me what I'm missing.


The scenario:

I'm working on a game engine... and right now I'm trying to get a test map displayed on screen. It's tile based, and each tile is a 2D quad. The tiles are all arranged into two GLfloat buffers on map load -- one to hold the verteces, and the other for the texture coords.

The method:

Rather than using display lists, I'm going with the gl____Pointer + glDrawArrays method. So actully drawing the map looks like the following:


glBindTexture(GL_TEXTURE_2D, layertexture);

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glVertexPointer(2,GL_FLOAT,0,&mLayers[layer].verteces[0]);
glTexCoordPointer(2,GL_FLOAT,0,&mLayers[layer].textcoords[0]);

glDrawArrays(GL_QUADS,0,mLayers[layer].scr_len[0]);


The problem:

The map is drawing. However the texture is not. Instead of getting a nice tiled map image, I'm getting a big white square for the map -- as if texturing were disabled (quads are being rendered -- they're just not textured). I'm figuring there must be some step I'm skipping on setup. Here's the texture related calls I'm doing (in the order I do them):


on startup:
glEnable(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

on texture load:
glGenTextures
glBindTexture
glTexImage2D

on draw:
glBindTexture

on shutdown:
glDeleteTextures



It feels like I've been banging my head against the wall. I honestly don't have a clue why it isn't working. I've checked the buffer I'm passing to glTexImage2D and it seems to have the right image (or at least... the image contains no white pixels). glGetError reports no error after texture load.

At this point I'm seeking any idea on what the problem could be. I don't care how ridiculous. This is driving me nuts.

Thanks in advance.
Guy Perfect









Since: 11-18-05

Last post: 6340 days
Last view: 6338 days
Posted on 01-30-06 05:49 PM Link | Quote
Looks like all the GL calls are happening in the correct order... But for each of the things you mentioned after "on startup," you didn't show the exact syntax of what you were using. Do that, and a problem may be discoverable.

A way to verify if the texturing works is to input a simple shape by hand and set the texture coordinates by hand. If THAT works, then there's something in the way you're calling the vertex arrays that's not working correctly.

Also, as a rule of thumb, two triangles can be rendered faster than one quad. I recommend using GL_TRIANGLE_STRIP instead of GL_QUADS for your glBegin and glDrawArrays statements.
Disch

Red Cheep-cheep


 





Since: 12-10-05

Last post: 6617 days
Last view: 6617 days
Posted on 01-30-06 06:08 PM Link | Quote
I actually just now solved the problem with help from people on IRC.

Apparently GL was using the wrong mipmap level image of the texture for rendering. So I replaced glTexImage2D with gluBuild2DMipmaps and all is well.

Originally posted by BGNG
Also, as a rule of thumb, two triangles can be rendered faster than one quad. I recommend using GL_TRIANGLE_STRIP instead of GL_QUADS for your glBegin and glDrawArrays statements.


Yes... but triangle strips don't work well with 2D tiled maps since 2 of the 3 verteces of any triangle beyond the first are shared with the previous triangle. IE two tiles next to each other on the map will have to have graphics that are adjacent to each other on the texture.

Thanks for the reply ^^
Add to favorites | Next newer thread | Next older thread
Acmlm's Board - I3 Archive - Programming - GRAAAH OpenGL 2D texturing problem |


ABII

Acmlmboard 1.92.999, 9/17/2006
©2000-2006 Acmlm, Emuz, Blades, Xkeeper

Page rendered in 0.021 seconds; used 361.35 kB (max 424.54 kB)