SDL+OpenGL 2D program [3kb]

Hi! This post is about my essay to create a Tutorial about 2d Graphics with
sdl+opengl. I’ve tried to use only SDL but it is way slow. I don’t like to
use root+SDL_SETVIDEODRIVER, so I decided to use OpenGL (I DON’T use
Openglblit :slight_smile: ). Now I’m posting 2 versions of my first program. One uses
glDrawPixels that is very slow on 99% of the Pc’s. The other version uses
glVertex (I’ve tried with glRectf but I don’t know how to map a texture,
any idea?).
Now I need to do the same thing using only SDL to show what’s the
difference using OGL and SDL…
But I have some problems… I don’t know how to create a Tile engine. In
fact, my first Idea was to create it using SDL, but now with opengl I don’t
know how to build a virtual screen bigger than the actual screen. Example:
My screen is 640x480, but my tiled world is 1000x1000. How can I do it with
Opengl? Does I have to put everithing on a SDL surface and then draw it as
one big GL_Quads? (I think that’s stupid, because I lose the performances
of my hardware).
Can anybody help me?

ps. why this line doesn’t work in my program?
“glGetIntegerv(GL_MAX_PROJECTION_STACK_DEPTH,&maxdepth);”

If somebody think that my programs are interesting, I will put them on a
webpage with some docs…but first I have to leave some code from Sam (and
some other piece that I dont know )

(my email is ma0ATbigfootDOTcom - M A Zero , not O )
-------------- next part --------------
A non-text attachment was scrubbed…
Name: test.tar.gz
Type: application/x-gzip
Size: 3257 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20011219/4688441b/attachment.bin

Hi! This post is about my essay to create a Tutorial about 2d Graphics
with sdl+opengl. I’ve tried to use only SDL but it is way slow. I don’t
like to use root+SDL_SETVIDEODRIVER, so I decided to use OpenGL (I
DON’T use Openglblit :slight_smile: ). Now I’m posting 2 versions of my first
program. One uses glDrawPixels that is very slow on 99% of the Pc’s.
The other version uses glVertex (I’ve tried with glRectf but I don’t
know how to map a texture, any idea?).
Now I need to do the same thing using only SDL to show what’s the
difference using OGL and SDL…
But I have some problems… I don’t know how to create a Tile engine. In
fact, my first Idea was to create it using SDL, but now with opengl I
don’t know how to build a virtual screen bigger than the actual screen.
Example: My screen is 640x480, but my tiled world is 1000x1000. How can
I do it with Opengl? Does I have to put everithing on a SDL surface and
then draw it as one big GL_Quads? (I think that’s stupid, because I
lose the performances of my hardware).
Can anybody help me?

Check out the parallax scrolling examples on

http://olofson.net/mixed.html

(There’s also a simpler example with just one level… Where did it go?)

What you do (for each frame) is basically just to figure out what area of
the virtual map is currently covered by the screen, and then render all
tiles from that area. The approach is exactly the same with OpenGL and
SDL.

ps. why this line doesn’t work in my program?
“glGetIntegerv(GL_MAX_PROJECTION_STACK_DEPTH,&maxdepth);”

No idea… Why do you need it anyway? 2D applications generally don’t
push the projection stack very hard. (In glSDL, I’m changing it whenever
someone calls SDL_SetClipRect(), but that cannot be optimized with the
stack anyway. Don’t know if it would be faster to do the clipping some
other way; haven’t looked into it yet…)

If somebody think that my programs are interesting, I will put them on
a webpage with some docs…but first I have to leave some code from Sam
(and some other piece that I dont know )

Yeah, I’m messing with 2D on OpenGL as well, although my approach is
focused on getting ordinary (ie not OpenGL aware) applications to render
with OpenGL.

My code still isn’t available as a stand-alone package, but you can find
it in later versions of Kobo Deluxe, in graphics/glSDL.[ch]. Version
0.4-pre5 was released today, and contains the latest glSDL featurs and
fixes, as well as some improvements of the game.

http://olofson.net/download/kobodeluxe-0.4-pre5.tar.bz2
http://olofson.net/download/kobodeluxe-0.4-pre5.tar.gz

glSDL splits large surfaces up to handle the OpenGL texture size
limitations, as well as to utilize texture size optimally. (Textures have
to be square…) It can use multiple textures for a single surface to
handle either very wide or very tall surfaces, but wide and tall
surfaces aren’t handled as of now.

glSDL is also a pretty dirty hack in some areas, so don’t look too
carefully! :wink: (That applies to the SDL_Surface interfacing part in
particular - although at least, it’s not using ‘unused1’ as a pointer any
more…)

//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 20 December 2001 00:31, ma0 wrote:

David Olofson wrote:

Check out the parallax scrolling examples on

http://olofson.net/mixed.html

I’ll check them…thanks.

ps. why this line doesn’t work in my program?
“glGetIntegerv(GL_MAX_PROJECTION_STACK_DEPTH,&maxdepth);”

No idea… Why do you need it anyway? 2D applications generally don’t
push the projection stack very hard. (In glSDL, I’m changing it whenever

I don’t know :slight_smile: I’m playing with my examples…and I was thinking about how
to add sprites or anything else above my background (Now I spend my time
playing with Opengl and with RedAlert2: Yuri’s revenge… :-)…
How can I add a sprite on the screen if I don’t know where I am now?
I think that if I save the coords of a point like (0,0) then I can easily
add my sprites…I think that I have to use glPush|PopMatrix to do this?
Or not? (probably I must read the Ogl Bible before trying to programm
something)

If somebody think that my programs are interesting, I will put them on
a webpage with some docs…but first I have to leave some code from Sam
(and some other piece that I dont know )

Yeah,

I’ll try to create some simple code with many comments and i’ll put it on a
webpage soon. ( One man interested in my work is better than 0)

I’m messing with 2D on OpenGL as well, although my approach is
focused on getting ordinary (ie not OpenGL aware) applications to render
with OpenGL.

What do you mean with ordinary applications?

Ma0

[…]

ps. why this line doesn’t work in my program?
“glGetIntegerv(GL_MAX_PROJECTION_STACK_DEPTH,&maxdepth);”

No idea… Why do you need it anyway? 2D applications generally don’t
push the projection stack very hard. (In glSDL, I’m changing it
whenever

I don’t know :slight_smile: I’m playing with my examples…and I was thinking about
how to add sprites or anything else above my background (Now I spend
my time playing with Opengl and with RedAlert2: Yuri’s revenge… :-)…
How can I add a sprite on the screen if I don’t know where I am now?

Uhm, how can you not know where you are…? Is some other (3D) code
playing around with the projection matrix?

I think that if I save the coords of a point like (0,0) then I can
easily add my sprites…I think that I have to use glPush|PopMatrix to
do this? Or not?

No, why would you do that? All you have to do is passing suitable vertex
and texture coords for each vertex (ie four per quad). Use glOrtho() to
set up a coordinate system with (0,0) in the top-lef of the screen and
(640,480) (or whatever) in tho bottom right corner, and the vertex coords
can be ordinary screen coords, just as with a 2D API.

gl(Push|Pop)Matrix is only useful if you really need to switch between a
few matrices. For example, it might be useful for the 2D overlays in a 3D
game - but I’m not sure if there’s much point in doing that just to avoid
two projection matrix changes per frame.

(probably I must read the Ogl Bible before trying to programm something)

Yeah, that’s probably a good idea. :slight_smile:

If somebody think that my programs are interesting, I will put them
on a webpage with some docs…but first I have to leave some code
from Sam (and some other piece that I dont know )

Yeah,

I’ll try to create some simple code with many comments and i’ll put it
on a webpage soon. ( One man interested in my work is better than 0)

I’m messing with 2D on OpenGL as well, although my approach is
focused on getting ordinary (ie not OpenGL aware) applications to
render with OpenGL.

What do you mean with ordinary applications?

SDL applications (alright, games! :wink: that were written for the SDL 2D
API, rather than OpenGL.

That is, with glSDL, you write normal SDL code, using normal SDL_Surfaces
as with plain SDL, but the actual compiled code uses OpenGL for any
rendering to the screen. (It sends the graphics to texture RAM the first
time a surface actually is blitted to the screen, and then keeps track of
the textures.)

Eventually, glSDL might become a real rendering backend of SDL, so you
can use it with any SDL 2D application that isn’t using OpenGL normally.

//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 20 December 2001 23:45, ma0 wrote:

Hi! This post is about my essay to create a Tutorial about 2d Graphics with
sdl+opengl. I’ve tried to use only SDL but it is way slow. I don’t like to
use root+SDL_SETVIDEODRIVER, so I decided to use OpenGL (I DON’T use
Openglblit :slight_smile: ). Now I’m posting 2 versions of my first program. One uses
glDrawPixels that is very slow on 99% of the Pc’s. The other version uses
glVertex (I’ve tried with glRectf but I don’t know how to map a texture,
any idea?).
Now I need to do the same thing using only SDL to show what’s the
difference using OGL and SDL…
But I have some problems… I don’t know how to create a Tile engine. In
fact, my first Idea was to create it using SDL, but now with opengl I don’t
know how to build a virtual screen bigger than the actual screen. Example:
My screen is 640x480, but my tiled world is 1000x1000. How can I do it with
Opengl? Does I have to put everithing on a SDL surface and then draw it as
one big GL_Quads? (I think that’s stupid, because I lose the performances
of my hardware).
Can anybody help me?

The Renai project ( http://renai.sourceforge.net/ ) have quite a good
2D-engine which either draws the screen using plain SDL (“software
mode”) or using OpenGL textures (“hardware mode”).
The application is not aware which renderer is used.

For my own project “morgate”, a isometric Worldforge client
(http://www.worldforge.org) I have adapted their engine and mainly
improved the performance of the “software mode”.

You may get a recent snapshot from
http://www.ardanoldo.org/lonewolf/projects/morgate/morgate-0.9.8.tar.gz

Maybe you get some ideas from either source.On Thu, 20 Dec 2001, ma0 wrote:


Karsten-O. Laux
@Karsten_Laux