2D OpenGL Texture problem
Greetings,
I am working on making a 2D tile based game on OpenGL. My tiles are 26 pixels by 26 pixels. Because OpenGL can only support textures that have dimensions that are powers of 2, this leaves me with a problem(as a noob).
I can load my textures from 32x32 bitmap file and then just draw the lower left 26x26 pixels of them. This works great, but there’s wasted space in each file. If I am to have 100s and 100s of tiles that could be a problem. So instead I put all my tiles into a large 512x512 bitmap file.
My problem is that I can’t find a way to extract the tile that I want to draw(from the main file) onto the quad.
I have tried making each tile from the main file it’s own texture. But im not sure how to implement that(therefore I failed at that attempt). Plus I would like to keep my tiles as clear as possible.
Does anyone know of a way I could just draw a 26 pixel by 26 pixel portion from my main file that has all the tiles in it. ((Preferably using ints, floats seem to complicate things when working on 2D.))
Any insights or urls on how to accomplish is greatly appreciated. I have been tackling this problem for a few days now. :-)
=^_^=
Use glTexCoord2f(x,y)
where x and y are your texture locations, both values range from 0 to 1, so if you have a 512 texture, and you would like to access 77th pixel your x or y value would be 77/512
[edited by - YoFatMamma on August 28, 2003 12:53:10 AM]
where x and y are your texture locations, both values range from 0 to 1, so if you have a 512 texture, and you would like to access 77th pixel your x or y value would be 77/512
[edited by - YoFatMamma on August 28, 2003 12:53:10 AM]
Oh(Duh)... thanks! It’s a wonder how I got this far... and to think, I only failed one semester of math in high school.
=^_^=
Hrmm... well that kinda works, cept that I can only go diagonally starting at the lower left tile. I need to be able to locate any of the 26x26 pixel tiles in the 19x19 tile grid from the master file.
=^_^=
dude, u have to calculate 2 separate coordinates for x and y
example i want to access 22, 44 u do 22/512, 44/512
example i want to access 22, 44 u do 22/512, 44/512
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement