Sign in to follow this  

Textures, textcoords, tilemaps, optimization, transparency, tips?

This topic is 3457 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have some questions for you guys, if you dare to help me with this... these things have been bothering me for a long time, so i appreciate your help a lot. Here we go: 1) I readed this somewhere: "Make sure that you specify a texture coordinate before each vertex that makes up a face. If you have 3 verticies the pattern for texture mapping the triangle would go like this: TexCoord; VertexCoord; TexCoord; VertexCoord; TexCoord; VertexCoord; " Why i need to do that? I have sometimes used: "TexCoord; VertexCoord; VertexCoord; VertexCoord; VertexCoord; " and its working fine. 2) Do i really need to bind a texture even when i just need a plain color without any patterns in it, for example white text? feels stupid to bind texture for such simple things like that... 3) Is there a way to give texture coordinates in pixels? I cant make proper tilemaps by using float values as texture coordinates: sometimes it shows the near pixels of some other tiles when zoomed out (even when the filter is GL_NEAREST). I think it would fix every problems related to tile maps if the texture coordinates were given as pixels. 4) Would it be better to store the game textures in small squares, or as big squares as possible? or does it even matter as long as there arent million of different texture images? small would be something like 256x256 and big 2048x2048 etc. I heave heard that the texture binding procedure is one of the slowest functions you can use, which why im pondering this. 5) Whats the correct way to draw on the game screen, like health bars etc? How should it be done properly? i have problems to find the screen edges to position the quads there with their textures while i need to use the Z position in 3d rendering. 6) any tips? how should i draw tons of different tiles (3d game) when the tile images are in many different texture images, and without raping the texture bind command? Should I just draw those tiles first which are in the same texture image and then continue to another texture image for other tiles? 7) How i can draw GL_LINEAR filtered tilemaps properly without mixing the tile images to neighbour tiles? I heard something about using GL_CLAMP but it didnt make it different. 8) Why the hell are the texture coordinates upside down? Y-coordinate zero point is at bottom, when it should be at top... 9) Is there a good way to draw 256 colour paletted textures? or do i need to convert my paletted texture data into 32bit colors, and when i want to make some texture into different palet, i just redraw it and create new texture for it? 10) when i make 100% transparent pixel near some 0% transparent pixel, how do i prevent that the 0% pixel doesnt fade the color to the 100% transparent pixel color when using GL_LINEAR filter? Do i just need to set that 100% transparent pixel into the same color as the 0% pixel color was? i dont want to use any masking textures, just one quad which uses alpha blending. I hope someone understood my questions, or even just one question right. My english isnt so good... -- Best regards - Emark

Share this post


Link to post
Share on other sites
1) No, you don't have to. When you use TexCoord, all vertices defined thereafter will use these texture coords.

2) No, glDisable(GL_TEXTURE_2D) (or GL_TEXTURE_RECTANGLE_ARB or whatever target you're using) will work fine, and is recommended.

3) If you bind your texture to the GL_TEXTURE_RECTANGLE_ARB target, the texel coordinate is its position in the texture in pixels.

4) Yes, creating a texture atlas is a good idea (multiple textures in one texture), but don't make your giant texture bigger than the hardware can handle. You can query the maximum width and height of textures with glGet.

5) Render your 3D scene as normal, then disable Z testing (or clear the Z buffer if you still need to Z test) then draw the GUI elements in orthographic view.

6) Yes, render your geometry by order of texture so you can use glBindTexture as few times as possible.

7) Don't quite know what you mean about this, but it sounds like you might want to research texture borders.

8) Because. You can flip the texture matrix to reverse the coordinates if you like.

9) Paletting isn't supported in hardware any more, as far as I know, so you'll have to convert it.

10) ?

Share this post


Link to post
Share on other sites
7) put some distance between the tiles to avoid blending between tiles if you plan on putting all tiles on the same texture.
Never use GL_CLAMP. Use GL_CLAMP_TO_EDGE instead.

8) you can use the texture matrix to flip or you can flip the texture yourself or you flip the texcoord (1.0-texcoord.t)

Share this post


Link to post
Share on other sites
(8) It makes perfect sense actually. Have you ever had math class, and used a piece of graph paper? Where do you find 0 on the y-axis is in quadrant I. Yup, it's at the lower-left corner. So the fact is that OpenGL is just a more mathematic approach when it comes to coordinates.

Share this post


Link to post
Share on other sites
Quote:
2) No, glDisable(GL_TEXTURE_2D) (or GL_TEXTURE_RECTANGLE_ARB or whatever target you're using) will work fine, and is recommended.

Ah, i didnt realise i could just do that, thanks!

Quote:
3) If you bind your texture to the GL_TEXTURE_RECTANGLE_ARB target, the texel coordinate is its position in the texture in pixels.

Very much thanks! now its much more easier to coordinate stuff.

Quote:
4) Yes, creating a texture atlas is a good idea (multiple textures in one texture), but don't make your giant texture bigger than the hardware can handle. You can query the maximum width and height of textures with glGet.
But is it better to use the max size of texture or something else? like, does it get slower with the biggest size?

Quote:
8) you can use the texture matrix to flip or you can flip the texture yourself or you flip the texcoord (1.0-texcoord.t)

What do you mean by "use the texture matrix to flip" ? any example?

Share this post


Link to post
Share on other sites
Quote:
Original post by Emark


Quote:
4) Yes, creating a texture atlas is a good idea (multiple textures in one texture), but don't make your giant texture bigger than the hardware can handle. You can query the maximum width and height of textures with glGet.
But is it better to use the max size of texture or something else? like, does it get slower with the biggest size?

The same pixels, that is the same amount of graphics card memory, with less per-texture overhead: large atlases cannot be slower than separate small textures, and reducing texture switching is a net gain.
Quote:

Quote:
8) you can use the texture matrix to flip or you can flip the texture yourself or you flip the texcoord (1.0-texcoord.t)

What do you mean by "use the texture matrix to flip" ? any example?


There is a matrix stack that transforms the original texture coordinates before they're actually used.

glMatrixMode(GL_TEXTURE);
...
glScalef(1.0f,-1.0f,1.0f);



But it's meant for useful purposes, like reusing the same texture coordinate data with global modifications or performing some nontrivial computation; using the same texture coordinates as the rest of the world would be easier and cheaper.

10) You are correct, the transparent texel needs to have a colour that matches the adjacent opaque texels, otherwise the wrong colour bleeds. Where does the different colour come from?

Share this post


Link to post
Share on other sites

This topic is 3457 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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