🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

A few questions

Started by
5 comments, last by Shadowwoelf 16 years, 6 months ago
I just have a few questions on certain topics in opengl hope you can help me out. 1. If I wanted to get the width and height of an image I would do something like this? width=TextureImage[0]->sizeX; hieght=TextureImage[0]->sizeY; 2. I am thinking of using a chipset for this 2d game I am creating. Would it be better to leave the texture in 480x256 or break it up into a display list? 3. In lesson 17 I was particularly wondering if I changed the 16 to 30 would it still function the same? cx=float(loop% -->16<-- )/16.0f; cy=float(loop/16)/16.0f; 4. In lesson 17 I was wondering why the texture coordiante is 16 glVertex2i(16,0); wouldn't that loop it? Thanks for the help
Advertisement
1. yes, but it depends on your texture loader, often that information is only available when loading the texture and is then discarded later on, so if you want to retain that info you have to save that particular data elsewhere at load time.

2. it's better to have it in one big texture, just not 480x256 as not all graphics cards can handle NPOT textures, try the nearest power of two texture size 512x256.
Regarding display lists, well that's one way to go, it works well in lessons 17, but otherwise i wouldn't recommend using them.

3. obviously no, that bit of code divides the texture coordinates in a 16x16 grid, if you change 16 to 30 you would get a grid of 30x30

4. no, glVertex2i(16,0); refers to the vertex coordinates of the characters and these are always 0 or 16 in this case, but could really be any number, the lower the number the smaller the font.
It's glTexCoord2f that sets the texture coordinates.
So what other ways should I go when using a chipset for my 2d game? Simply have a loop that will go through all my tiles? for example

while(!loop){

glBindTexture(GL_TEXTURE_2D, texture[filter]);
glTranslatef(y,x,0.0f);//move it up and down the screen
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);

filter=tileset+1;
x+=16;//move it 16 pixels to the left
y+=16;//move it 16 pixels down
}

or is there a different approach I could take?

Thanks for your help
Pretty much, but don't bind the texture for each loop, it's way to expensive.
if you have a large amount of tiles all in the same texture that doesn't change then i suggest using VBO, or at least a vertex array
I am not quite sure what you mean by VBO or vertex array. The only problem I see is that I have to loop at least 1,200 times just to draw a screen that is 640x480. Any suggestions?
VBO or vertex arrays allows you to put all(or most) of the 1200 tiles in a array that can be drawn using only one command.

Either way, having a loop of 1200 polygons is not that much unless each of them has a unique texture file, in that case i would suggest you start using a texture atlas.
Thanks for your help. Its much appreciated.

This topic is closed to new replies.

Advertisement