2d+3d

Hi,

is it and if how is it possible to Blit a SDL_Surface, after rendering with
OpenGL?

Thanks in advance
Hannes

Hi,

is it and if how is it possible to Blit a SDL_Surface, after rendering
with
OpenGL?

Thanks in advance
Hannes

There are two ways to do this (that I know off).

Number one, is using SDL_OPENGLBLIT instead of SDL_OPENGL. This will allow
both rendering and blitting to the OpenGL window.

However, the prefered way (in terms of performance) to do this, is loading
the SDL_Surface into an OpenGL texture and then rendering a 2D textured quad
in Ortho mode. Here’s how you do that, after you have loaded the surface
into a texture:

Suppose your screen is width x height, then this code should allow for pixel
perfect “blitting” in OpenGL:

/* Set 2D matrices */
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, width, 0, height, -1, 1);

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

/* Example of some 2D rendering

  • Draws a fullscreen textured quad
    */
    glBindTexture(GL_TEXTURE_2D, hudTextureID);
    glBegin(GL_QUADS);
    glTexCoord2f(0,1)
    glVertex2i(0,height);
    glTexCoord2f(0,0)
    glVertex2i(0,0);
    glTexCoord2f(1,0)
    glVertex2i(width,0);
    glTexCoord2f(1,1)
    glVertex2i(width,height);

glEnd();

/* Restore 3D matrices */
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();

And an additional tip: Those width and height variables don’t actually have
to match your
OpenGL window’s resolution. That’s a handy thing to support multiple
resolutions. For instance
you could set glOrtho to 640x480 even though the window is 800x600. All the
rendering will get
enlarge automatically by OpenGL.

Regards,

Dirk Gerrits

----- Original Message -----
From: el_bosso@web.de (Hannes Niederhausen)
To:
Sent: Tuesday, 19 February, 2002 20:50
Subject: [SDL] 2D+3D

Hi all!
Just a question:
Why the heck do y’all want to render 2d-stuff in Ortho-Mode? Normally you
should know your actual gluLookAt() or whatever your using, so switching to
ortho-mode just takes time to change the projection matrix. If you use
gluLookAt (which I prefer, cause it’s really easy to use once you
understood how it works) in this way:

gluLookAt(cam_x, cam_y, cam_z, center_x, center_y, center_z, up_x,up_y,up_z);

Then you draw your quad like this:

glBindTexture(GL_TEXTURE_2D,yourtexture);
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex3f(cam_z-center_z,cam_z-center_z,center_z);
glTexCoord2f(1,0); glVertex3f(-(cam_z-center_z),cam_z-center_z,center_z);
glTexCoord2f(1,1); glVertex3f(-(cam_z-center_z),-(cam_z-center_z),center_z);
glTexCoord2f(0,1); glVertex3f(cam_z-center_z,-(cam_z-center_z),center_z);
glEnd();

no f*cking switching to Ortho-Mode neccessary!!!
got it?

St0fF 64

At 21:12 19.02.2002 +0100, you wrote:>----- Original Message -----

From: “Hannes Niederhausen” <el_bosso at web.de>
To:
Sent: Tuesday, 19 February, 2002 20:50
Subject: [SDL] 2D+3D

Hi,

is it and if how is it possible to Blit a SDL_Surface, after rendering
with
OpenGL?

Thanks in advance
Hannes

There are two ways to do this (that I know off).

Number one, is using SDL_OPENGLBLIT instead of SDL_OPENGL. This will allow
both rendering and blitting to the OpenGL window.

However, the prefered way (in terms of performance) to do this, is loading
the SDL_Surface into an OpenGL texture and then rendering a 2D textured quad
in Ortho mode. Here’s how you do that, after you have loaded the surface
into a texture:

Suppose your screen is width x height, then this code should allow for pixel
perfect “blitting” in OpenGL:

/* Set 2D matrices */
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, width, 0, height, -1, 1);

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

/* Example of some 2D rendering

  • Draws a fullscreen textured quad
    */
    glBindTexture(GL_TEXTURE_2D, hudTextureID);
    glBegin(GL_QUADS);
    glTexCoord2f(0,1)
    glVertex2i(0,height);
    glTexCoord2f(0,0)
    glVertex2i(0,0);
    glTexCoord2f(1,0)
    glVertex2i(width,0);
    glTexCoord2f(1,1)
    glVertex2i(width,height);

glEnd();

/* Restore 3D matrices */
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();

And an additional tip: Those width and height variables don’t actually have
to match your
OpenGL window’s resolution. That’s a handy thing to support multiple
resolutions. For instance
you could set glOrtho to 640x480 even though the window is 800x600. All the
rendering will get
enlarge automatically by OpenGL.

Regards,

Dirk Gerrits


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

Hi all!
Just a question:
Why the heck do y’all want to render 2d-stuff in Ortho-Mode? Normally you
should know your actual gluLookAt() or whatever your using, so switching
to
ortho-mode just takes time to change the projection matrix. If you use
gluLookAt (which I prefer, cause it’s really easy to use once you
understood how it works) in this way:

gluLookAt(cam_x, cam_y, cam_z, center_x, center_y, center_z,
up_x,up_y,up_z);

Then you draw your quad like this:

glBindTexture(GL_TEXTURE_2D,yourtexture);
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex3f(cam_z-center_z,cam_z-center_z,center_z);
glTexCoord2f(1,0); glVertex3f(-(cam_z-center_z),cam_z-center_z,center_z);
glTexCoord2f(1,1);
glVertex3f(-(cam_z-center_z),-(cam_z-center_z),center_z);
glTexCoord2f(0,1); glVertex3f(cam_z-center_z,-(cam_z-center_z),center_z);
glEnd();

no f*cking switching to Ortho-Mode neccessary!!!
got it?

St0fF 64

For your information, gluLookAt changes the modelview matrix so you’ll still
need a PushMatrix, LoadIdentity and PopMatrix. Unless you don’t need to save
the modelview matrix, then you only need the LoadIdentity call.

So perhaps gluLookAt may be a bit faster. I doubt it is easier for most
though. Also, you can increase the glOrtho performance if you build the
ortho view once and keep it stored in memory. For gluLookAt you’d have to
calculate it at least each time the camera changes position / angle.

Dirk Gerrits

Not only is it not actually any better, but it also brings in dependency
for GLu, an external library. While in large these things are taken for
granted in the UNIX world and the Linux part of it in particular, external
deps add exponential levels of complexity to user support for any binary
release. This is particularly significant for win32 users. Their OS
comes ill-equipped to compile anything more complex than a grocery list,
and some around here question its ability for even that. :wink:

However, gluLookAt is definitely the wrong solution to the overlay
problem. If the glOrtho turns out to be a serious speed hit (it hasn’t
been in any program/driver combination I’ve tried), then I agree you
should fix the problem by caching the transformed matrix. Just don’t
forget to check a flag to determine whether or not the matrix needs to be
retransformed after things like resolution changes. We save neither the
matrix generated by glFrustum nor by glOrtho currently, though we do cache
the arguments passed to the former, and we use the physical window
resolution for the latter.

If it ain’t broke…On Wed, Feb 20, 2002 at 08:08:58AM +0100, Dirk Gerrits wrote:

For your information, gluLookAt changes the modelview matrix so you’ll still
need a PushMatrix, LoadIdentity and PopMatrix. Unless you don’t need to save
the modelview matrix, then you only need the LoadIdentity call.

So perhaps gluLookAt may be a bit faster. I doubt it is easier for most
though. Also, you can increase the glOrtho performance if you build the
ortho view once and keep it stored in memory. For gluLookAt you’d have to
calculate it at least each time the camera changes position / angle.


Joseph Carter Here we go again

!netgod:! time flies when youre using linux
!doogie:
! yeah, infinite loops in 5 seconds.
!Teknix:! has anyone re-tested that with 2.2.x ?
!netgod:
! yeah, 4 seconds now

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 273 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020220/113f224d/attachment.pgp

Not only is it [gluLookAt] not actually any better, but it also brings in
dependency
for GLu, an external library.

Not necessarily. It’s pretty easy to create your own lookat function. But as
you and I both said, it’s not likely to be faster than the Ortho solution.
And indeed Ortho needs neither GLu nor a self-made function.

Dirk Gerrits

----- Original Message -----
From: knghtbrd@bluecherry.net (Joseph Carter)
To:
Sent: Wednesday, 20 February, 2002 9:53
Subject: Re: [SDL] 2D+3D

Well, I was looking at it from my point of view which is using gluLookAt
thru the whole programm, not changing it, except for resizing. As I do
demo-coding, this is the easiest way. The argument, that glu adds another
library doesn’t really count unless you really don’t use any glu-related
stuff. I do! And AFAIK glu is distributed (under windoof) right next to
opengl, so it doesn’t matter at all, 'cause you just link it to glu32.dll.
So if you use lookat, you should have some statics with the lookat-params,
and then this is a faster solution, cause no! loadidentity and stuff is needed.
St0fF 64

At 13:55 20.02.2002 +0100, you wrote:>----- Original Message -----

From: “Joseph Carter”
To:
Sent: Wednesday, 20 February, 2002 9:53
Subject: Re: [SDL] 2D+3D

Not only is it [gluLookAt] not actually any better, but it also brings in
dependency
for GLu, an external library.

Not necessarily. It’s pretty easy to create your own lookat function. But as
you and I both said, it’s not likely to be faster than the Ortho solution.
And indeed Ortho needs neither GLu nor a self-made function.

Dirk Gerrits


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

Dirk Gerrits wrote …

Hannes Niederhausen wrote …

is it and if how is it possible to Blit a SDL_Surface, after
rendering with OpenGL?

There are two ways to do this (that I know off).

Number one, is using SDL_OPENGLBLIT instead of SDL_OPENGL.
This will allow both rendering and blitting to the OpenGL window.

However, the prefered way (in terms of performance) to do this, is
loading the SDL_Surface into an OpenGL texture and then rendering
a 2D textured quad in Ortho mode.

I think he was asking the other way around. It sounded like he wanted to use
OpenGL to render a 3D model onto a 2D surface and then use the surface as a
2D sprite in “normal” SDL. I can imagine some uses for that since I
currently do something similar off-line in my 3D modeling tool, taking
"snapshots" of different animation frames and creating a set of bitmaps.

Doing it with OpenGL, you would basically use the 3D models at run-time to
generate a series of sprite animation frames based on the current zoom
setting, player color selections, rotation, etc. The big problem is that you
normally have to do a lot of “pixel-tweaking” to get small renderings to
look right as 2D sprites.

  • Randi

Regimental Command
Generic Armored Combat System
http://regcom.sourceforge.net

No I really only want to draw a SDL_Surface over my 3D stuff, e.g. a
control Panal which is only a 2D Bitmap.
I also knew the possibility of the ortho mode, but what doe’s me intruding
is the power of 2 texturesize.

PS: If you work on a 3D modeling tool, do you use multi windowing, and if
yes how?

             Hannes

At 23:32 20.02.02 -0600, you wrote:>Dirk Gerrits wrote …

Hannes Niederhausen wrote …

is it and if how is it possible to Blit a SDL_Surface, after
rendering with OpenGL?

There are two ways to do this (that I know off).

Number one, is using SDL_OPENGLBLIT instead of SDL_OPENGL.
This will allow both rendering and blitting to the OpenGL window.

However, the prefered way (in terms of performance) to do this, is
loading the SDL_Surface into an OpenGL texture and then rendering
a 2D textured quad in Ortho mode.

I think he was asking the other way around. It sounded like he wanted to use
OpenGL to render a 3D model onto a 2D surface and then use the surface as a
2D sprite in “normal” SDL. I can imagine some uses for that since I
currently do something similar off-line in my 3D modeling tool, taking
"snapshots" of different animation frames and creating a set of bitmaps.

Doing it with OpenGL, you would basically use the 3D models at run-time to
generate a series of sprite animation frames based on the current zoom
setting, player color selections, rotation, etc. The big problem is that you
normally have to do a lot of “pixel-tweaking” to get small renderings to
look right as 2D sprites.

  • Randi

Regimental Command
Generic Armored Combat System
http://regcom.sourceforge.net


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

Hannes Niederhausen wrote …

No I really only want to draw a SDL_Surface over
my 3D stuff, e.g. a control Panal which is only
a 2D Bitmap.

Oops, never mind … :slight_smile:

PS: If you work on a 3D modeling tool, do you
use multi windowing, and if yes how?

What I meant was “when using a commercial 3D modeling tool”. I render each
frame, cut, paste, tweak, palletize … a very long and tedious process. The
last on I played with was a BattleMech composed of two pieces (upper/lower)
rendered in six rotations (0/60/120/180/240/300 degrees), two colors
(gold/silver), and three zoom factors (1x/2x/3x), for a total of 72
different bitmaps.

  • Randi

Regimental Command
Generic Armored Combat System
http://regcom.sourceforge.net

About the “multi windowing,” are you talking about multiple viewports in
a single window? if yes, you probably want to use the OpenGL Scissor
Test. (Decent tutorial on nehe.gamedev.net )

No I’M talking about multiple windows with multiple viewprts, like a 3D map
editor with 4 views (top, left, right and perspective.
It should also work with one window, scissorin and SDL_Surfaces as Buttons.
I don’t understand what you guys have against the SDL_OPENGLBLIT, I like
having the option to ix 2D and 3D things.

At 01:35 22.02.02 -0600, you wrote:>About the “multi windowing,” are you talking about multiple viewports in

a single window? if yes, you probably want to use the OpenGL Scissor
Test. (Decent tutorial on nehe.gamedev.net )


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

I don’t understand what you guys have against the SDL_OPENGLBLIT, I
like
having the option to ix 2D and 3D things.

If you peek at the SDL source code you will find out that SDL_OPENGLBLIT
creates four 256x256 quads and splits the blitted surface onto it. Very
inefficient. It’s far more efficient to upload the image to a texture
and draw a quad with the image as a texture. This way you also have no
conversion, and the images are all in texture memory (OR AGP Memory
which is slower.) But you have to keep in mind that Video cards have a
limited amount of video memory, and that reading anything back from the
video card is painfully slow. So the idea is upload to the card, and
never modify the texture to keep performance.

That’s what I did with renai.sf.net , it’s messy, it originally started
as C code, there are hacks to cut images onto 4 256x256 textures for
3DFX cards (which is quite the waste of time.) and some other horrible
inefficient things that are nasty. Mainly SDL_TTF is unusable. I’m
looking at FTGL to try and make OpenGL render text and have pre-render
caching, because it is not pleasant to render a string as several images
and figure out the positions, and then have to upload a new text-image
every time. Even worse when you want to make a “typed” look where the
text is progressive. Have to render the entire string again but with an
additional letter(or use scissorbox or stencil clipping.) Very slow, and
you can’t have a variable-width texture (with 256x256 3DFX hacks, it
becomes insanely stupid.)

Anyways I realized what the problem was going to be with OPENGLBLIT and
didn’t use it.

No I really only want to draw a SDL_Surface over my 3D stuff, e.g. a
control Panal which is only a 2D Bitmap.
I also knew the possibility of the ortho mode, but what doe’s me
intruding is the power of 2 texturesize.

Either use multiple quadratic textures, put quadratic tiles in the same
textur, or implement a function that tile rectangular images into a
texture - or just steal some code from glSDL! :slight_smile:

PS: If you work on a 3D modeling tool, do you use multi windowing, and
if yes how?

It’s usually done by setting up multiple OpenGL contexts.

(BTW, it’s easy for me to tell which applications do that, as that
particular feature is broken on Matrox G400 cards - regardless of OS, it
seems! Matrox says it’s a driver bug, but they have have know about it
for years, and not been able to fix it! I’m starting to suspect that it’s
actually a hardware flaw - broken synchronization commands or
something… :frowning: )

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Thursday 21 February 2002 11:13, Hannes Niederhausen wrote:

PS: If you work on a 3D modeling tool, do you use multi windowing, and
if yes how?

It’s usually done by setting up multiple OpenGL contexts.

I meant using SDL, is it possible to open multiple SDL-windows?

     Hannes

SDL 1.2 does not support this unfortunately. The necessary support is
only about half-implemented. It would require an API change to fix this,
and therefore it will have to wayt for SDL 1.3 development to begin.

A warning, multiple windows in OpenGL does not work with some hardware,
and even with some hardware it is supposed to work in, it doesn’t actually
work right.On Sat, Mar 02, 2002 at 12:38:18PM +0100, Hannes Niederhausen wrote:

PS: If you work on a 3D modeling tool, do you use multi windowing, and
if yes how?

It’s usually done by setting up multiple OpenGL contexts.

I meant using SDL, is it possible to open multiple SDL-windows?


Joseph Carter glDisable (DX8_CRAP);

The deafening silence taught me not to ask a bunch of geeks for advice
from their girlfriends

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 273 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020302/9ee437ca/attachment.pgp

No, not in current versions - and there’s no difference between OpenGL
and “SDL 2D” in that regard.

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Saturday 02 March 2002 12:38, Hannes Niederhausen wrote:

PS: If you work on a 3D modeling tool, do you use multi windowing,
and if yes how?

It’s usually done by setting up multiple OpenGL contexts.

I meant using SDL, is it possible to open multiple SDL-windows?