2D above OpenGL graphics

Hi,

I’ve very new to SDL. I’m working on a SDL OpenGL based application.
I would love to have 2D things provided by SDL above the OpenGL, as a
upper layer.

It is possible to do this?

Is there any tutorial on this?

Many thx,

Best regards,

Nuno Santos

Hi Nuno,

Yes it is possible

I’m not sure if there’s a tutorial but I am doing this in my current
project.

Orthogonal view matrix is a good term to help you do what you want.

Also you will probably want to make sure that back face culling is OFF as
well as the depth buffer checking> ----- Original Message -----

From: sdl-bounces+atrix2=cox.net@libsdl.org
[mailto:sdl-bounces+atrix2=cox.net at libsdl.org] On Behalf Of Nuno Santos
Sent: Saturday, November 18, 2006 5:16 PM
To: A list for developers using the SDL library. (includes SDL-announce)
Subject: [SDL] 2D above OpenGL graphics

Hi,

I’ve very new to SDL. I’m working on a SDL OpenGL based application.
I would love to have 2D things provided by SDL above the OpenGL, as a
upper layer.

It is possible to do this?

Is there any tutorial on this?

Many thx,

Best regards,

Nuno Santos


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

If you mean using the SDL 2D APIs like SDL_BlitSurface on top of
OpenGL, then you probably don’t want to do this. There is a deprecated
option called SDL_OPENGLBLIT which allowed this, but there are a lot
of fundamental problems with this, so don’t use it.

If you use OpenGL, then everything should be OpenGL including your 2D
stuff. One thing you could try if it makes sense is to draw SDL 2D
things into memory/textures, and draw the textures in OpenGL scene.

-Eric> Date: Sun, 19 Nov 2006 01:15:37 +0000

From: Nuno Santos
Hi,

I’ve very new to SDL. I’m working on a SDL OpenGL based application.
I would love to have 2D things provided by SDL above the OpenGL, as a
upper layer.

It is possible to do this?

Is there any tutorial on this?

Many thx,

Best regards,

Nuno Santos

Hi,

Yes, i was meaning that! I see!

My first goal in that direction was to include some text above my
scenes! Do you recommend me the same strategy?

Cheers,

Nuno

E. Wing escreveu:> If you mean using the SDL 2D APIs like SDL_BlitSurface on top of

OpenGL, then you probably don’t want to do this. There is a deprecated
option called SDL_OPENGLBLIT which allowed this, but there are a lot
of fundamental problems with this, so don’t use it.

If you use OpenGL, then everything should be OpenGL including your 2D
stuff. One thing you could try if it makes sense is to draw SDL 2D
things into memory/textures, and draw the textures in OpenGL scene.

-Eric

Date: Sun, 19 Nov 2006 01:15:37 +0000
From: Nuno Santos <@Nuno_Santos>
Hi,

I’ve very new to SDL. I’m working on a SDL OpenGL based application.
I would love to have 2D things provided by SDL above the OpenGL, as a
upper layer.

It is possible to do this?

Is there any tutorial on this?

Many thx,

Best regards,

Nuno Santos


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

Nuno Santos wrote:

Hi,

Yes, i was meaning that! I see!

My first goal in that direction was to include some text above my
scenes! Do you recommend me the same strategy?

Cheers,

Nuno

Hoy.
Opengl can be a very good 2d api.

Just do:

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

glOrtho2d(0, screenWidth, 0, screenHeight);

glMatrixMode(GL_MODELVIEW);
// some 2d drawing like

glRasterPos2i(100, 100); // draw at position 100 100 pixel
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, ‘H’); // Will draw a H at 100
100, for more advanced text handling or if you don’t wanna link with
glut, check the opengl.org site for font rastering, SDL also provide
true type library.

glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();

Some tips:

Always draw your 2d (interface or anything) AFTER the scene.

Disable as much option as you can (man glPushAttrib) like depth test,
blending (you need it if image has alpha value), texture, lighting…
before drawing the 2d layer.

Regards–
Kuon
CEO - Goyman.com SA
http://www.goyman.com/

“Computers should not stop working when the users’ brain does.”
-------------- next part --------------
A non-text attachment was scrubbed…
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3271 bytes
Desc: S/MIME Cryptographic Signature
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20061120/69e390b5/attachment.bin

Hi,

I’ve tried your code but i dont know what linker option should i use
to have to get glOrtho2d recognized.

I also don’t understand what he does. Can you make me a resume?

I putted it in my render function, in the end, just before glSwapBuffes

Can you give me some lights here?

Cheers,

NunoEm Nov 20, 2006, ?s 9:43 AM, kuon - Nicolas Goy - ??? escreveu:

Nuno Santos wrote:

Hi,
Yes, i was meaning that! I see!
My first goal in that direction was to include some text above my
scenes! Do you recommend me the same strategy?
Cheers,
Nuno

Hoy.
Opengl can be a very good 2d api.

Just do:

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

glOrtho2d(0, screenWidth, 0, screenHeight);

glMatrixMode(GL_MODELVIEW);
// some 2d drawing like

glRasterPos2i(100, 100); // draw at position 100 100 pixel
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, ‘H’); // Will draw a H at
100 100, for more advanced text handling or if you don’t wanna link
with glut, check the opengl.org site for font rastering, SDL also
provide true type library.

glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();

Some tips:

Always draw your 2d (interface or anything) AFTER the scene.

Disable as much option as you can (man glPushAttrib) like depth
test, blending (you need it if image has alpha value), texture,
lighting… before drawing the 2d layer.

Regards


Kuon
CEO - Goyman.com SA
http://www.goyman.com/

“Computers should not stop working when the users’ brain does.”


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

Hi,

I’ve tried your code but i dont know what linker option should i use
to have to get glOrtho2d recognized.

That is his own function or something like that.
The function you should use is glOrtho.

glOrtho( 0, width, 0, height, 0.0, 1.0 );
should be fine.On Wednesday 22 November 2006 15:17, Nuno Santos wrote:

I also don’t understand what he does. Can you make me a resume?

I putted it in my render function, in the end, just before
glSwapBuffes

Can you give me some lights here?

Cheers,

Nuno

Em Nov 20, 2006, ?s 9:43 AM, kuon - Nicolas Goy - ??? escreveu:

Nuno Santos wrote:

Hi,
Yes, i was meaning that! I see!
My first goal in that direction was to include some text above my
scenes! Do you recommend me the same strategy?
Cheers,
Nuno

Hoy.
Opengl can be a very good 2d api.

Just do:

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

glOrtho2d(0, screenWidth, 0, screenHeight);

glMatrixMode(GL_MODELVIEW);
// some 2d drawing like

glRasterPos2i(100, 100); // draw at position 100 100 pixel
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, ‘H’); // Will draw a H at
100 100, for more advanced text handling or if you don’t wanna link
with glut, check the opengl.org site for font rastering, SDL also
provide true type library.

glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();

Some tips:

Always draw your 2d (interface or anything) AFTER the scene.

Disable as much option as you can (man glPushAttrib) like depth
test, blending (you need it if image has alpha value), texture,
lighting… before drawing the 2d layer.

Regards


Kuon
CEO - Goyman.com SA
http://www.goyman.com/

“Computers should not stop working when the users’ brain does.”


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

Ok,

I now got something, but my 3D gets very weird and almost doest shows
up.

I would love to have this font rastering on while the 3D stuff is
under it.

Is it possible?

I also don’t know what is happening with that code.

This is what i got:

void renderScene(void) {
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

eyeX = sin(angle);
eyeZ = -cos(angle);
		
glLoadIdentity();

gluLookAt((eyeX*c.ex)*zoom,c.ey+eyeY,(eyeZ*c.ez)*zoom,
		c.cx,c.cy,c.cz,
		0.0f,1.0f,0.0f);
			

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

glOrtho( 0, 640, 0, 480, 0.0, 1.0 );


glMatrixMode(GL_MODELVIEW);
// some 2d drawing like

glRasterPos2i(50, 50); // draw at position 0 100 pixel
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, 'H'); // Will draw a H at  

100 100, for more advanced text handling or if you don’t wanna link
with glut, check the opengl.org site for font rastering, SDL also
provide true type library.

glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();


glutSwapBuffers();

}Em Nov 22, 2006, ?s 6:31 PM, Sami N??t?nen escreveu:

glOrtho( 0, width, 0, height, 0.0, 1.0 );

Ok,

I now got something, but my 3D gets very weird and almost doest
shows up.

I would love to have this font rastering on while the 3D stuff is
under it.

Is it possible?

I also don’t know what is happening with that code.

This is what i got:

void renderScene(void) {
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

eyeX = sin(angle);
eyeZ = -cos(angle);

glLoadIdentity();

gluLookAt((eyeX*c.ex)zoom,c.ey+eyeY,(eyeZc.ez)*zoom,
c.cx,c.cy,c.cz,
0.0f,1.0f,0.0f);

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

glOrtho( 0, 640, 0, 480, 0.0, 1.0 );

glMatrixMode(GL_MODELVIEW);
// some 2d drawing like

glRasterPos2i(50, 50); // draw at position 0 100 pixel
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, ‘H’); // Will draw a H at
100 100, for more advanced text handling or if you don’t wanna link
with glut, check the opengl.org site for font rastering, SDL also
provide true type library.

glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();

glutSwapBuffers();
}

glOrtho( 0, width, 0, height, 0.0, 1.0 );

_

Just a note to the list, I helped Nuno privately.

For reference, the error in the above code is

glMatrixMode(GL_MODELVIEW);

missing just after glClear. I usualy set the matrixMode I want to
use, that’s why I don’t restore it after my 2d “context”.

the glOrtho2d was a typo, it’s glOrtho or gluOrtho2D.

Best regardsOn 23 Nov 2006, at 02:10, Nuno Santos wrote:

Em Nov 22, 2006, ?s 6:31 PM, Sami N??t?nen escreveu:


Kuon
CEO - Goyman.com SA
http://www.goyman.com/

“Computers should not stop working when the users’ brain does.”

-------------- next part --------------
A non-text attachment was scrubbed…
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2434 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20061127/bd9900fe/attachment.bin