• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# using opengl for effects on a 2d game...

## Recommended Posts

Greetings, i almost finished a little 2d puzzle game for LINUX and windows. Now that i am waiting for the last pictures, i thought i could add some nice looking opengl effects. I thought about water/wave or plasma effects, drawn over the playground/splash screen. The problem is that i have no idea where to start. I have a copy of the red book, but i am in need of some more specific information. Please post a reply if you have some usefull information or if know a good tutorial. Thanks in advance, Mike

##### Share on other sites
Greetings again,
is it raaly a that strange idea to use opengl just as an enhancement for a 2d game?
I just ask because i was''nt able to find any useful tutorials/demos....

##### Share on other sites
how did you have done it till now?

using sdl? then it should be not that big problem. nehe has one tutorial about drawing 2d-stuff, where he shows you a complete game in 2d. you can use this as a simple base to learn coding in opengl. good luck, have fun

##### Share on other sites
Hi again,
yes i worte the linux version with sdl.
The problem with the water effect is that i am short on cpu time, so i thougt using opengl for the water effect would not be that calculation intensive as computing the water effect through the cpu. But i am uncertain in this assumtion...
Unfortunatly i was not able to find an opengl water demo...

##### Share on other sites
Hi again,
yes i worte the linux version with sdl.
The problem with the water effect is that i am short on cpu time, so i thougt using opengl for the water effect would not be that calculation intensive as computing the water effect through the cpu. But i am uncertain in this assumtion...
Unfortunatly i was not able to find an opengl water demo...

##### Share on other sites

1- when do you want it to appear ?
often or not ?

2- where do you want it ?
in the menus ? in the game ?
more likely in the center of the screen ? in a corner ?
faded in background ? on top of every drawing ?

3- which size so you want it to have ?
a little effect for some puzzle pads ? an effect that fulfills the entire screen (eg to fade between a screen and another) ?

The answers of this questions, and maybe other questions too, will help us what effect to propose. a big quality effect or not, a cpu-intensive effect or not, etc.

##### Share on other sites
Hello Vincoof,
The main problem is that the effect should use as less cpu time as possible but also should look as good as possible.
To be honest i thougt i could use some opengl features that leads to a water effect instead of calculating it on the cpu.
Mike

1- when do you want it to appear ? - in the game
often or not ? - i thougt about one water frame for every second displayed frame

2- where do you want it ? - on one of the source surfaces
more likely in the center of the screen ? 80% to 100% of the surface
in a corner ? - full surface would be nice
faded in background ? - would be nice, but doesn''t matter
on top of every drawing ? - just on top of one of the surfaces

3- which size so you want it to have ? 640x460 (480 is fine too)
an effect that fulfills the entire screen (eg to fade between a screen and another) ? should only be drawn over one of the source surfaces

##### Share on other sites
Correct me if I''m wrong, but you''d like to have an effect water over the puzzle, where the objects start to fall :
(if the puzzle game is a tetris-like)

  |          ||**********||          ||          ||          ||          ||          | ----------

The dash lines would be the border of the puzzle, and the stars would be where the water lies.

If no, could you please a post a representation (either horrible text or beatiful image) of what the puzzle *roughly* look like and where you would like to draw the "source surface" ?

##### Share on other sites
immagine minesweeper with a grayscale background pickture on the part of the playground that is not jet opened/discovered. The hiden surface is the one i like to animate with a water effect.
So at the beginning the entire screen would look like grayscale water. As soon as a sqare of the puzzle is solved the sqare of the grayscale source surface will be replaced with a sqare from a colored surface.
Here''s a littel graphic to illustrate hwo it should look:
********************
********************
*****XXXXXXXXX******
*****XXXXXXXXX******
*****XXXXXXXXX******
*****XXXXXXXXX******
********************
********************

X are discoverd, colored sqares (no water)
* are grayscale, hiden sqares (that should look like there''s some water over the picture)

Vincoof, thank''s for your interest and please dont get me wrong, but i would like to write the water effect myself. (I am currently short on cpu time so i have to do it in assembly language). Some code that illustrates how do programm a water effect would be nice, but i would prefer a tutorial/explanation about how to do it.
I also would share the code if anybody is interested, but i first need some information about how to write it.
However,
thanks so far,
Mike

##### Share on other sites
Hmm. I think the most simple, the most efficient and also the most realistic method would be to build a giant quadstrip and animate the water by moving the quad corners "randomly" into the Z axis.

This way it would not cost a lot of cpu (you can optimize the moving water because calling rand() for each corner would cost too much) and it would be very easy to "dig" the water as the puzzle evolves.

Do you see what I mean ?
If yes, what do you think of it ?

##### Share on other sites
Hi vincoof,
i found a demo on demonews.com that works exactly on that way. I''ll try to get it to work with sdl and direct draw this weekend.
And if i got it to work i maybe write a small concept for a tutorial that explains the background of the code.

##### Share on other sites
I am not a 100% sure, but I believe that if you are going to use SDL and OpenGL you cant use standard SDL surfaces and video functions, you have to use OGL for all your video needs, again, I am not 100% sure.