OpenGL Texture Atlas with short? - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: OpenGL Texture Atlas with short? (/thread-1996.html)
OpenGL Texture Atlas with short? - Graphic Ace - Dec 23, 2008 07:57 PM
Can you create a OpenGL Texture Atlas with short & if so How?
Because right not I am using float value of 0.0625 for (16x16 TileSet of a 512x512 Image) An I can't figure out how to create tiles with short & I have read that short & unsigned byte are best for texturing.
OpenGL Texture Atlas with short? - arekkusu - Dec 23, 2008 08:44 PM
Your options depend on which API you're using.
TexCoordPointer treats bytes/shorts as unnormalized values, so you're passing integral (0, 1, 2...) texture coordinates to the vertex transformation. You can scale them arbitrarily before you sample the texture, for example with the texture matrix. In this case, you're trading off submitting fewer bytes per vertex for a couple extra operations per vertex, so benchmark carefully.
VertexAttribPointer takes a "normalized" flag which lets you convert the byte/short to a float in the range [0,1]. You're still able to transform the data before using it.
OpenGL Texture Atlas with short? - Graphic Ace - Dec 23, 2008 09:29 PM
So do I have to use a certain Function to change them into a decimal value or something. Sorry I am a little bit confused by all this.
You would think that if you are going to use int value it would be used like
0->32 by 0->32 for a 32x32 TileSprite
if you could show me an Example or value of a apart of a image I think i could figure out faster
Thanks so far for letting me know there is a way to make a Texture Atlas with short.
OpenGL Texture Atlas with short? - arekkusu - Dec 24, 2008 12:02 AM
Graphic Ace Wrote:0->32 by 0->32 for a 32x32 TileSpriteMost of the time, texture coordinates in OpenGL are treated as floats where the range [0,1] maps to the entire texture image.
It's done this way because of how texture sampling works-- a texture is not just a 2D array of pixels. It can be a mipmap with multiple images, and/or a cubemap where the texture coordinate is used as a 3D vector. Only after the texture sampler has chosen the appropriate cubemap face and/or mipmap level is the float coordinate scaled to the dimension of the texture to fetch texels. Textures also have a set of parameters to control how texels are filtered when fetched, how coordinates outside [0,1] are handled, and various other options.
It's also possible to use denormalized texture coordinates, with ARB_texture_rectangle or with the texelFetch() samplers in EXT_gpu_shader4 and GL3.
All of that discussion is separate from how you actually pass coordinates in, though.
Quote:if you could show me an ExampleWhat API are you using, and what hardware are you targeting?
OpenGL Texture Atlas with short? - Graphic Ace - Dec 25, 2008 03:32 AM
I am using Cocoa & OpenGL an I programming for
All Mac Computers
an so on..
OpenGL Texture Atlas with short? - arekkusu - Dec 26, 2008 12:56 PM
In that case, stick to the lowest common denominator, OpenGL ES1.1 on the iPhone:
TexCoordPointer() to pass in coordinates as bytes or shorts
MatrixMode() and Scalef() etc to transform the coordinates to a range you like
DrawArrays() or DrawElements() to submit vertex data
but keep in mind what works best on the iPhone won't necessarily be best for the other renderers.
OpenGL Texture Atlas with short? - donny - Dec 30, 2008 03:13 PM
Graphic Ace Wrote:Because right not I am using float value of 0.0625 for (16x16 TileSet of a 512x512 Image) An I can't figure out how to create tiles with short & I have read that short & unsigned byte are best for texturing.
Well a 'short' in C/C++ is an integer value, so you could not have the value 0.0625 (well... it's a fixed-point value, you can interpret that fixed point wherever you want it.)
If you want to make things easier on yourself, you can transform the texture matrix.