Jump to content

  • Log In with Google      Sign In   
  • Create Account

Last post about 2D in OpenGL (so please stop!)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
34 replies to this topic

#1 Dwarf with Axe   Members   -  Reputation: 277

Like
Likes
Like

Posted 18 July 2002 - 11:12 AM

Are you guys just lazy!? There have been thousands of posts along the lines of "How do I do 2d in OpenGL" to "Duuuhde, I wunt too maek a two dee gaem in ohpun jee el; how do eye set uhp two dee???!?" I have developed a simple, nice, pretty way for all of you to have your 2D fun.
  
void glEnable2D()
{
	int vPort[4];

   glGetIntegerv(GL_VIEWPORT, vPort);

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

   glOrtho(0, vPort[2], 0, vPort[3], -1, 1);
   glMatrixMode(GL_MODELVIEW);
   glPushMatrix();
   glLoadIdentity();
}

void glDisable2D()
{
   glMatrixMode(GL_PROJECTION);
   glPopMatrix();   
   glMatrixMode(GL_MODELVIEW);
   glPopMatrix();	
}

  
To use these two functions, simply call glEnable2D(), draw whatever you want to have 2D''d, then call glDisable2D(). Here''s an example:
  
void RenderScene()
{
  glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
  glLoadIdentity();
  
  glEnable2D();
    glBegin(GL_TRIANGLES);
      glColor3ub(255, 0, 0);
        glVertex2d(0, 0);
      glColor3ub(0, 255, 0);
        glVertex2d(100,0);
      glColor3ub(0, 0, 255);
        glVertex2D(50, 50);
    glEnd();
  glDisable2D();
}
  
See? Nice and small; Nice and simple. So please friends, don''t ask how to setup OpenGL in 2D mode... Because now you know. ~Jesse Lawson

Sponsor:

#2 Damocles   Members   -  Reputation: 133

Like
Likes
Like

Posted 18 July 2002 - 11:15 AM

Duuuude! How duh ya set up toodee in OGL? :D

#3 Dwarf with Axe   Members   -  Reputation: 277

Like
Likes
Like

Posted 18 July 2002 - 12:07 PM

lol...

Hope the code works for you peepohl

~Jesse

#4 Tarkus   Members   -  Reputation: 122

Like
Likes
Like

Posted 19 July 2002 - 07:54 PM

Thank you, very helpful...

#5 Dwarf with Axe   Members   -  Reputation: 277

Like
Likes
Like

Posted 20 July 2002 - 02:33 PM

This was just a way for me to simply say that there is an alternative to asking a question that someone else has already asked. So happy happy joy joy man!

Yeah baby, yeahhhh..
~ Jesse

#6 ZoomBoy   Members   -  Reputation: 162

Like
Likes
Like

Posted 20 July 2002 - 02:39 PM

The best thing to do is store this message URL for further reference.

And then cut and paste.


ZoomBoy
Developing a iso-tile 2D RPG with skills, weapons, and adventure. See my old Hex-Tile RPG GAME, character editor, diary, 3D Art resources at Check out my web-site


#7 henrym   Members   -  Reputation: 102

Like
Likes
Like

Posted 20 July 2002 - 03:35 PM

Lol! Dwarf, this is a legendary thread dude.

Im actually about to start a 2D game in OGL, but Im not up to doing the graphics (actually still in design ATM), but your post means I don''t have to look up MSDN.

I''ve bookmarked this thread and I''ll recommend it for anyone else who posts asking how to do 2D in OpenGL.

Henrym
My Site

#8 Khawk   Senior Staff   -  Reputation: 1362

Like
Likes
Like

Posted 20 July 2002 - 04:06 PM

I added it to the forum FAQ. Now you just have to point people there.


Kevin "Khawk" Hawkins
CEO and News Director, GameDev.net
Author, OpenGL Game Programming
Developer Diary



#9 Dwarf with Axe   Members   -  Reputation: 277

Like
Likes
Like

Posted 21 July 2002 - 05:50 AM

Well thanks everyone. I''m glad this can help BTW! My new project (as of last month really) is gl2d, a site dedicated to 2D Game Development in OpenGL.

You can check it out at http://www.jesse.luethy.net, or click here

I hope many can benefit from it, and have fun!
~ Jesse

OpenGL_2D Project

#10 Dougie   Members   -  Reputation: 122

Like
Likes
Like

Posted 27 March 2004 - 11:41 AM

Great functions man. Thanks ALOT, now I don''t have to spend weeks working out how to do this.

#11 Ilici   Members   -  Reputation: 862

Like
Likes
Like

Posted 27 March 2004 - 08:57 PM

quote:
Original post by Khawk
I added it to the forum FAQ. Now you just have to point people there.




People actually read that? The link to the FAQ should be half the size of the screen and say: "Read the FAQ or i will come to your house and eat your children." that should make it more effective.


Oh and Dwarf with Axe: how about some code for quad and rendering arbitrary sized bitmaps?

#12 Pipo DeClown   Members   -  Reputation: 804

Like
Likes
Like

Posted 24 May 2004 - 05:29 AM

Nice one Dwarf. Although I use DirectX, I think this really rocks

--
You''re Welcome,
Rick Wong
- Google | Google for GameDev.net | GameDev.net''s DirectX FAQ. (not as cool as the Graphics and Theory FAQ)


#13 DudeMiester   Members   -  Reputation: 156

Like
Likes
Like

Posted 24 May 2004 - 12:25 PM

People need to ask about this kind of thing?! wow... My opinion of humanity just dropped down a notch.

#14 Deranged   Members   -  Reputation: 606

Like
Likes
Like

Posted 24 May 2004 - 12:30 PM

I NOMINATE STICKY! Seriously this would mean no more 2d questions.



Sharp Basic - Coming summer 2004!
Sign Up For Sharp Basic Beta Testing!!!

#15 owl   Banned   -  Reputation: 364

Like
Likes
Like

Posted 24 May 2004 - 07:10 PM

something (probably very easy) i couldn''t figure out is how to draw things in ortho using the default (float) cartesian space instead of using pixels...

Does somebody knows how to do it?

#16 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 24 May 2004 - 08:54 PM

quote:
Original post by Ilici
The link to the FAQ should be half the size of the screen and say: "Read the FAQ or i will come to your house and eat your children." that should make it more effective.


Probably wouldn''t work so well. People who can''t find the FAQ are usually newbies. Newbies tend to be kids. Kids don''t have children.

How about "Read the FAQ or i will send a hideous winged deamon to haunt you and scare away the chicks, so that you''ll NEVER lose you virginity. MUHAHAHAH!"? Hmmm, not very catchy either

#17 Venerable Vampire   Members   -  Reputation: 151

Like
Likes
Like

Posted 25 May 2004 - 05:48 AM

quote:
Original post by owl
something (probably very easy) i couldn''t figure out is how to draw things in ortho using the default (float) cartesian space instead of using pixels...

Does somebody knows how to do it?


Use gluOrtho2D(0,1,0,1); to set up the proj matrix.

--------------------------------------------------------
Life would be so much easier if we could just get the source code.

#18 Puzzler183   Members   -  Reputation: 540

Like
Likes
Like

Posted 25 May 2004 - 11:48 AM

OpenGL can just be annoying with 2D stuff. Things being a pixel off; it being a pixel off in various implementations, etc. is just irritating and is one reason I put my engine on hold. Also, the OpenGL PixelCopy functions are ridiculously slow.

I get the impression that things like that are more of a problem than setting up a window (although that can confuse people too)...

#19 weyland   Members   -  Reputation: 122

Like
Likes
Like

Posted 25 May 2004 - 04:46 PM

Thanks from the bottom of my heart for making this thread sticky ...

If I ever see one more "how do I place a font/bitmap/jpg/HUD/tilebased/whateva on the screen in 2D" thread I''m leaving for Vegas

#20 Puzzler183   Members   -  Reputation: 540

Like
Likes
Like

Posted 30 May 2004 - 04:02 AM

The thing is sometimes stuff is a pixel off if you use a textured quad and if you use PixelCopy, you get HORRIBLE performance. So actually, sometimes questiuons can be reasonable.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS