OpenGL tile based game question

Hi

I want to write a tile based game using SDL/OpenGL. I want to realize
each field/unit by a texturized quad.

My question is this - which is the easiest to draw the field:

  • create a OpenGL texture for each of the 4 rotated views of each texture
  • rotate the texture during drawing (can I do that by changing the
    texture coordinates?)
  • rotate the quad?

Thanks for your help.

Heya Tobias,

I think the easiest would be #2 - changing the texture coordinates to rotate
the texture

PS this may be considered off topic for the SDL list since people dont
usualy talk about general game programming techniques here, more like they
talk about the SDL libs, problems they have with them, enhancements they
want made to them etc.

For discussions on OpenGL and game programming techniques you may want to
check out www.gameprogrammer.com and subscribe to that mailing list. Many
people from this list are also on that list as well (me included) so head on
over! (:> ----- Original Message -----

From: iso8859-1@gmx.de (Tobias Langner)
To:
Sent: Tuesday, February 22, 2005 10:08 AM
Subject: [SDL] OpenGL tile based game question

Hi

I want to write a tile based game using SDL/OpenGL. I want to realize
each field/unit by a texturized quad.

My question is this - which is the easiest to draw the field:

  • create a OpenGL texture for each of the 4 rotated views of each texture
  • rotate the texture during drawing (can I do that by changing the
    texture coordinates?)
  • rotate the quad?

Thanks for your help.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

PS this may be considered off topic for the SDL list since people dont
usualy talk about general game programming techniques here, more like they
talk about the SDL libs, problems they have with them, enhancements they
want made to them etc.

For discussions on OpenGL and game programming techniques you may want to
check out www.gameprogrammer.com and subscribe to that mailing list. Many
people from this list are also on that list as well (me included) so head on
over! (:

first: thx for your help.

second: I thought I’d ask here (instead of some usenet OpenGL-Group)
since at least one of my solutions (the first) included operations
before creating the texture and this would have been done (I hope) by
some function in libSDL - or at least manipulation of SDL_Surfaces.
That’s why I thought I should ask my question here.

Tobias Langner wrote:

I want to write a tile based game using SDL/OpenGL. I want to realize
each field/unit by a texturized quad.

I’ve been experimenting with the same thing (using PyGame)…

My question is this - which is the easiest to draw the field:

  • create a OpenGL texture for each of the 4 rotated views of each texture

“Free” rotation is one of the big wins for using OpenGL to render
something like this, the other being “free” alpha blending…

  • rotate the texture during drawing (can I do that by changing the
    texture coordinates?)

I’m not an expert, but IIRC the texture co-ordinates are used to specify
which parts of the texture are drawn, and they can be used to mirror the
texture, but not rotate it.

  • rotate the quad?

That’s probably the easiest approach, IMHO.

Thanks for your help.

That’s what we’re here for! ;-)–
Chris Herborth (@Chris_Herborth)
Never send a monster to do the work of an evil scientist.

Chris Herborth wrote:

Tobias Langner wrote:

  • rotate the texture during drawing (can I do that by changing the
    texture coordinates?)

I’m not an expert, but IIRC the texture co-ordinates are used to specify
which parts of the texture are drawn, and they can be used to mirror the
texture, but not rotate it.

Yes, you can rotate it too. If you were going to do this to draw your
normal quad:

glTexCoord2f(0.0, 0.0); glVertex2f(-0.5, -0.5);
glTexCoord2f(1.0, 0.0); glVertex2f(0.5, -0.5);
glTexCoord2f(1.0, 1.0); glVertex2f(0.5, 0.5);
glTexCoord2f(0.0, 1.0); glVertex2f(-0.5, 0.5);

you could rotate if 90 degrees to the left by doing instead:

glTexCoord2f(0.0, 1.0); glVertex2f(-0.5, -0.5);
glTexCoord2f(0.0, 0.0); glVertex2f(0.5, -0.5);
glTexCoord2f(1.0, 0.0); glVertex2f(0.5, 0.5);
glTexCoord2f(1.0, 1.0); glVertex2f(-0.5, 0.5);

You can even have OpenGL transform the texture coordinates for you by
using the GL_TEXTURE matrix:

glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glRotatef(42.0f, 0.0f, 0.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);

I’m not sure, but there may be a (slight?) performance hit for using the
GL_TEXTURE matrix.–
Jon

I think the easiest would be #2 - changing the texture coordinates
to rotate
the texture----- Mensaje original -----

Not only easiast but optimal :wink:
Using 4 separate textures it’s a waste of memory, and using rotations
just to flip it’s a waste of power (IMHO)

----- Mensaje original -----
over! (:

U got me there with that flipped smiley :slight_smile: