OpenGL Texture Atlas with short?

Member
Posts: 23
Joined: 2007.12
Post: #1
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.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #2
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.
Quote this message in a reply
Member
Posts: 23
Joined: 2007.12
Post: #3
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.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #4
Graphic Ace Wrote:0->32 by 0->32 for a 32x32 TileSprite
Most 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 Example
What API are you using, and what hardware are you targeting?
Quote this message in a reply
Member
Posts: 23
Joined: 2007.12
Post: #5
I am using Cocoa & OpenGL an I programming for

All Mac Computers

MacBook
iMac
iPhone
an so on..
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #6
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.
Quote this message in a reply
Apprentice
Posts: 5
Joined: 2008.12
Post: #7
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.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL ES Texture Masking airfire 6 15,034 Mar 17, 2014 07:07 PM
Last Post: baioses
  OpenGL ES Texture Compression ajrs84 9 4,480 May 7, 2013 03:36 PM
Last Post: ajrs84
  OpenGL ES Texture Masking dalasjoe sin 0 3,899 Apr 13, 2012 12:17 AM
Last Post: dalasjoe sin
  Texture in OpenGL ES 2 looks pixelated vunterslaush 18 23,826 Aug 30, 2011 09:44 PM
Last Post: Frogblast
  Lighting and changing texture colors in OpenGL agreendev 2 7,811 Aug 13, 2010 03:47 PM
Last Post: agreendev