LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 07-15-2004, 05:03 PM   #1
R00ts
Member
 
Registered: Mar 2004
Location: Austin TX, USA
Distribution: Ubuntu 11.10, Fedora 16
Posts: 545

Rep: Reputation: 30
Using OpenGL (+SDL) for 2D programs


Hi. I'm working on a 2D game (see sig) and after reading thru the SDL newsgroup I've given thought to using OpenGL for rendering graphics in two dimensional space only. So now my problem is finding a good guide to help me accomplish this. I'm well aware of http://nehe.gamedev.net/ and I've glanced briefly thru the tutorials there, but everything seems to be 3D based and quite honestly I don't want to spend time learning how to use OpenGL for 3D imaging if I'm never going to use it. Of course I will use the tutorials on there to learn about cell shading, lighting, etc., but I just need a simple guide to help me get started. I don't have a great deal of experience with graphic programming, but I've managed to implement video code in my game so far using the SDL_image library, which was very easy (and fun) to learn and use.


So does anyone have any sources that can help me get my feet wet with using OpenGL in a 2D application? I've tried googling myself and looked around the SDL website but couldn't find what I was looking for. Thanks for any help you can provide.
 
Old 07-15-2004, 07:39 PM   #2
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 50
using opengl for 2d is essentially using it in 3d with a constant coordinate(probably z). the only opengl you need to know how to do is placing and texturing quads which is essentially covered in nehe 2&6 but going through nehe 1-6 wouldnt do you any harm.

i dont think effects like lighting or blending will work if you dont do stuff in 3d cos they dont really make sense in 2d so if you want to use them your gonna have to learn 3d anyway.
 
Old 07-15-2004, 08:55 PM   #3
R00ts
Member
 
Registered: Mar 2004
Location: Austin TX, USA
Distribution: Ubuntu 11.10, Fedora 16
Posts: 545

Original Poster
Rep: Reputation: 30
Well the game is a top-down approach like Final Fantasy games. So what if I want to do something like say, in a dark dungeon I darken the screen that isn't within a certain circular radius of the character? Or what if I want to do something like simulate clouds overhead casting shadows on the ground? That makes sense to do in 2D, doesn't it? Thanks for your help though, I'll read tutorials 1-6 so I can have a strong backbone, even if I don't necessarily use everything I learn there.
 
Old 07-16-2004, 09:13 AM   #4
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
As Kev82 said, you're likely going to just need to know how to draw textured quads. Your circular lighting, and cloud shadow idea can be done by blending quads together, so you'll want to look at blending a bit too.

You could use OpenGL lights for the circle of light, but unless your quads are highly tessellated (that is, you define them with lots of verticies), you probably won't get the effect you want. OpenGL does lighting on a per-vertex basis, so if you are shining an OpenGL spotlight in the middle of a quad, and it touches no vertices, you will see no light.

You'd probably be better off with a "light map" technique, where you have your lighted area defined by another texture, in which you blend with the quads you've already drawn. Essentially the same technique could be used for your cloud shadows.

Depending on the hardware you are targetting, you might also want to look at multi-texturing (drawing polygons that have more than 1 texture assigned to them). Multitexturing should be supported on pretty much any card worth its 3d capabilities, but might not be on some ancient cards that were never really meant for 3d gaming.
 
Old 07-16-2004, 01:33 PM   #5
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Rep: Reputation: 32
Here is some source to draw a so-called "sprite":

glEnable(GL_BLEND);
glBlencFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glBind(MySpriteTexture);

glBegin(GL_QUADS)
glTexcoord2i(0,0);
glVertex2i(-10, -10);
glTexcoord2i(1,0);
glVertex2i(-10, 10);
glTexcoord2i(1,1);
glVertex2i(10, 10);
glTexcoord2i(0,1);
glVertex2i(10, -10);
glEnd();

glFlush();
SDL_Swap_GL_Buffer(); //Don't think this is the right call... but you get the idea
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using SDL/OpenGL, need help. kornerr Programming 33 11-20-2005 12:19 AM
sdl / opengl - cant press up and right atrain Linux - Games 2 03-28-2005 12:29 AM
Question about SDL OpenGL and -lglut doody Programming 2 11-16-2004 05:17 PM
OpenGL and SDL programming with Slackware zsejk Slackware 13 08-03-2004 08:52 PM
OpenGL lighting with SDL MadCactus Programming 0 09-21-2003 12:52 PM


All times are GMT -5. The time now is 04:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration