Jump to content
  • Advertisement
Sign in to follow this  
Kwizatz

OpenGL Using non normalized texcoords (how to?)

This topic is 5459 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

Hi, I am looking for a way to use non normalized texcoords (0..w,0..h instead of 0..1,0..1) the same way they must be used with the GL_ARB_texture_rectangle extension, but without using the extension. Currently I am calculating the width and height of a pixel by dividing 1/width and 1/height, and then multiplying with the value I need, this works, but sometimes the image gets distorted from one computer to another. Also, if anyone knows how to use a texture Atlas (look for the "Atlas Comparison Viewer" on this page) on OpenGL, I would really like to know how, since this kind of thing is exactly what I am doing. [smile]

Share this post


Link to post
Share on other sites
Advertisement
The only way to use values 0..N is to adjust the scale in the texture matrix. I e, you'd do:


glMatrixMode( GL_TEXTURE );
glLoadIdentity();
glScalef( 1.0/width, 1.0/height, 1 );
glMatrixMode( GL_MODELVIEW );


This is no different from what you're doing, though. Some (crappier) cards will not implement GL texel fetches correctly, so you can't make a perfect pixel match on all cards. Make it work on Intel Extreme, ATI Radeon and NVIDIA GeForce, and then the rest will work if they're compliant enough.

If you want to get pixel accurate fetches, remember that when you rasterize a fragment, the texel coordinate used comes from the interpolated position of the center of that fragment. Thus, the first texel sampled is a little bit in from the first texture coordinate given. If you have pixels == coordinates, and use as many pixels as your texture is wide, then the texture coordinates [0..1] will match pixels to texels 1:1. In this case, it also helps to turn on GL_NEAREST filtering, rather than linear or mip mapped. However, if you need rotation, then you need filtering, too.

Also make sure that all your textures are powers of two each direction -- if you're using gluBuildMipMaps() to upload, then non-power-of-two sizes will put filtering artifacts into your texture image, and you can't make perfect pixel matches.

The texture atlases they are talking about on that NVIDIA page are usually known as "texture sheets". They are commonly used on consoles to avoid switching textures. A "texture atlas" is usually used to describe a (usually automatically generated) unique UV map of a mesh to the [0..1,0..1] range. If you want to automatically generate a texture sheet, you should google for "texture sheeting" or, perhaps "power-of-two subdivision allocator"

Share this post


Link to post
Share on other sites
Ok, Thanks

actually I am not using mipmaps, this is to render font characters to the screen, if there is no real improvement between what I am doing and scaling the texture matrix, then I probably shouldn't bother.

I'll look up texture sheeting now, again Thanks.

Share this post


Link to post
Share on other sites
Maybe stupid question :
what is the difference between what you're looking for and a glTexCoord2f used for each vertex ( i use this for HUD tile drawing from a single texture )?

Share this post


Link to post
Share on other sites
Quote:
Original post by Kaeltyk
Maybe stupid question :
what is the difference between what you're looking for and a glTexCoord2f used for each vertex ( i use this for HUD tile drawing from a single texture )?


Just that GL_ARB_texture_rectangle (which I use if available on the card) uses non normalized texcoords, and with GL_TEXTURE_2D I have to find out the pixel dimensions and then multiply my Texture coords (which are in pixels, not 0..1) by these pixel dimensions, I figured I could avoid the calculations, and I figured it was posible to use non normalized texcoords, since GL_ARB_texture_rectangle does, but I was wrong [smile].

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!