# SDL/OpenGL

Hi all,

Not sure if this is SDL or OpenGL related, I am trying to simple rotate
a QUAD (yes very newbie question) but am not getting the results I want.
Basically what’s happening is that the QUAD is rotating around the top
left vertex and not around the quad’s center. I would like it to rotate
around the center of the quad. This this how OpenGL works or am I doing
something wrong? The code is as follow:

``````glPushMatrix();	//push projection onto stack
glTranslatef(mPosition.x,mPosition.y,mPosition.z);
glRotatef(rotation,0.0f,0.0f,1.0f);//rotate around z axis
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(0.0f, 0.0f);
glVertex2f(64.0f, 0.0f);
glVertex2f(64.0f, 32.0f);
glVertex2f(0.0f, 32.0f);
glEnd();
glPopMatrix();
``````

This is how my projection matrix is set up:

glViewport(0, 0, 640, 480);
glMatrixMode(GL_PROJECTION);
glOrtho(0.0f,640,480,0,-1.0f,1.0f);
glMatrixMode(GL_MODELVIEW);

Any help would be gladly appreciated.

-Byron

This is an OpenGL question. Check out these sites for great tutorials
on OpenGL:

nathanOn Wed, 2002-09-11 at 21:29, Byron Wright wrote:

Hi all,

Not sure if this is SDL or OpenGL related, I am trying to simple rotate
a QUAD (yes very newbie question) but am not getting the results I want.
Basically what’s happening is that the QUAD is rotating around the top
left vertex and not around the quad’s center. I would like it to rotate
around the center of the quad. This this how OpenGL works or am I doing
something wrong? The code is as follow:

glPushMatrix(); //push projection onto stack
glTranslatef(mPosition.x,mPosition.y,mPosition.z);
glRotatef(rotation,0.0f,0.0f,1.0f);//rotate around z axis
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(0.0f, 0.0f);
glVertex2f(64.0f, 0.0f);
glVertex2f(64.0f, 32.0f);
glVertex2f(0.0f, 32.0f);
glEnd();
glPopMatrix();

This is how my projection matrix is set up:

glViewport(0, 0, 640, 480);
glMatrixMode(GL_PROJECTION);
glOrtho(0.0f,640,480,0,-1.0f,1.0f);
glMatrixMode(GL_MODELVIEW);

Any help would be gladly appreciated.

-Byron

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

yeah…its easy…try this, change your vertexes to this:

glVertex2f(-32.0, -16.0f);
glVertex2f(32.0f, -16.0f);
glVertex2f(32.0f, 16.0f);
glVertex2f(-32.0f, 16.0f);

when you rotate something, it rotates from (0,0,0), so if you want your quad
to be rotated from the center, you need to make it so the center of the quad
is centered at (0,0,0) like above.

OpenGL rocks doesnt it? Im glad SDL supports it (:> ----- Original Message -----

From: bslayerw@mindspring.com (Byron Wright)
To: “SDL Mailing List”
Sent: Wednesday, September 11, 2002 6:29 PM
Subject: [SDL] SDL/OpenGL

Hi all,

Not sure if this is SDL or OpenGL related, I am trying to simple rotate
a QUAD (yes very newbie question) but am not getting the results I want.
Basically what’s happening is that the QUAD is rotating around the top
left vertex and not around the quad’s center. I would like it to rotate
around the center of the quad. This this how OpenGL works or am I doing
something wrong? The code is as follow:

glPushMatrix(); //push projection onto stack
glTranslatef(mPosition.x,mPosition.y,mPosition.z);
glRotatef(rotation,0.0f,0.0f,1.0f);//rotate around z axis
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(0.0f, 0.0f);
glVertex2f(64.0f, 0.0f);
glVertex2f(64.0f, 32.0f);
glVertex2f(0.0f, 32.0f);
glEnd();
glPopMatrix();

This is how my projection matrix is set up:

glViewport(0, 0, 640, 480);
glMatrixMode(GL_PROJECTION);
glOrtho(0.0f,640,480,0,-1.0f,1.0f);
glMatrixMode(GL_MODELVIEW);

Any help would be gladly appreciated.

-Byron

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

Thank you that worked.> ----- Original Message -----

Atrix Wolfe
Sent: Wednesday, September 11, 2002 6:38 PM
To: sdl at libsdl.org
Subject: Re: [SDL] SDL/OpenGL

yeah…its easy…try this, change your vertexes to this:

glVertex2f(-32.0, -16.0f);
glVertex2f(32.0f, -16.0f);
glVertex2f(32.0f, 16.0f);
glVertex2f(-32.0f, 16.0f);

when you rotate something, it rotates from (0,0,0), so if you want your
quad to be rotated from the center, you need to make it so the center of
the quad is centered at (0,0,0) like above.

OpenGL rocks doesnt it? Im glad SDL supports it (:

----- Original Message -----
From: @Byron_Wright (Byron Wright)
To: “SDL Mailing List”
Sent: Wednesday, September 11, 2002 6:29 PM
Subject: [SDL] SDL/OpenGL

Hi all,

Not sure if this is SDL or OpenGL related, I am trying to simple
rotate a QUAD (yes very newbie question) but am not getting the
results I want. Basically what’s happening is that the QUAD is
rotating around the top left vertex and not around the quad’s center.
I would like it to rotate around the center of the quad. This this how

OpenGL works or am I doing something wrong? The code is as follow:

glPushMatrix(); //push projection onto stack
glTranslatef(mPosition.x,mPosition.y,mPosition.z);
glRotatef(rotation,0.0f,0.0f,1.0f);//rotate around z axis
glVertex2f(0.0f, 0.0f);
glVertex2f(64.0f, 0.0f);
glVertex2f(64.0f, 32.0f);
glVertex2f(0.0f, 32.0f);
glEnd();
glPopMatrix();

This is how my projection matrix is set up:

glViewport(0, 0, 640, 480);
glMatrixMode(GL_PROJECTION);
glOrtho(0.0f,640,480,0,-1.0f,1.0f);
glMatrixMode(GL_MODELVIEW);

Any help would be gladly appreciated.

-Byron

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

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

Not sure if this is SDL or OpenGL related, I am trying to simple rotate
a QUAD (yes very newbie question) but am not getting the results I
want.
Basically what’s happening is that the QUAD is rotating around the top
left vertex and not around the quad’s center. I would like it to rotate
around the center of the quad. This this how OpenGL works or am I doing
something wrong? The code is as follow:

First rotate, then translate - multiplication of transformation
matrices is not commutative (I really need a mathametical
german-english dictionary … =) - meaning:

Translate -> rotate is different from rotate -> translate

You’re always rotating around the center of your coordinate system. So
if you want only your quad rotated first translate it to 0,0,0, rotate
and after this translate back.

Ciao
Arne

Hi,

I’m new to this list, so let me introduce myself.
My name is Nils Hesse, I’m 16 years old and from germany.
I’m programming since about 3 years.

Now my problem:
I know how to put a pixel with SDL, shure, but how can I get the RGB value of a pixel
from a bitmap, which is loaded as SDL_Surface and as an OpenGL texture?
Should I use OpenGL functions or some from the SDL?
Which can I use?

## Nur so’n Gedanke…

Die ?rzte - I Hate Hitler

## I hate Hitler! I hate him!

I can’t answer with regards to OpenGL, but for a normal SDL_Surface *,
you can examine the “pixels” element of the struct.

e.g.:

``````  p = (Uint8 *) (((Uint8 *)surface->pixels) +  /* Start at top of RAM */
(y * surface->pitch) +  /* Go down Y lines */
(x * bpp));             /* Go in X pixels */
``````

And then, depending on the value of ‘surface->format->BytesPerPixel’,
examine the “p” pointer in different ways.

I pretty much based my code on the tutorial found here:

http://sdldoc.csn.ul.ie/guidevideo.php

Good luck!

-bill!
bill at newbreedsoftware.com New Breed Software
http://www.newbreedsoftware.com/ Tux Paint 0.9.14 is out!On Mon, Nov 15, 2004 at 08:31:37PM +0100, slin at slin-online.de wrote:

Hi,

I’m new to this list, so let me introduce myself.
My name is Nils Hesse, I’m 16 years old and from germany.
I’m programming since about 3 years.

Now my problem:
I know how to put a pixel with SDL, shure, but how can I get the RGB value of a pixel
from a bitmap, which is loaded as SDL_Surface and as an OpenGL texture?

Hi again,

thanks a lot, this works.

Have a nice day…

Am 15 Nov 2004 um 11:39 hat Bill Kendrick geschrieben:

Hi,

I’m new to this list, so let me introduce myself.
My name is Nils Hesse, I’m 16 years old and from germany.
I’m programming since about 3 years.

Now my problem:
I know how to put a pixel with SDL, shure, but how can I get the RGB value of a
pixel> On Mon, Nov 15, 2004 at 08:31:37PM +0100, @slin_at_slin-online wrote:

from a bitmap, which is loaded as SDL_Surface and as an OpenGL texture?

I can’t answer with regards to OpenGL, but for a normal SDL_Surface *,
you can examine the “pixels” element of the struct.

e.g.:

``````  p = (Uint8 *) (((Uint8 *)surface->pixels) +  /* Start at top of RAM */
(y * surface->pitch) +  /* Go down Y lines */
(x * bpp));             /* Go in X pixels */
``````

And then, depending on the value of ‘surface->format->BytesPerPixel’,
examine the “p” pointer in different ways.

I pretty much based my code on the tutorial found here:

http://sdldoc.csn.ul.ie/guidevideo.php

Good luck!

-bill!
bill at newbreedsoftware.com New Breed Software
http://www.newbreedsoftware.com/ Tux Paint 0.9.14 is out!

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

## Nur so’n Gedanke…

Die ?rzte - I Hate Hitler