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

Started by
33 comments, last by vincoof 19 years, 10 months ago
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
----------[Development Journal]
Advertisement
Duuuude! How duh ya set up toodee in OGL? :D
------------------------------------------[New Delta Games] | [Sliders]
lol...

Hope the code works for you peepohl

~Jesse
----------[Development Journal]
Thank you, very helpful...
----------------------------Check out my crappy games...
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
----------[Development Journal]
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
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
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

Admin for GameDev.net.

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
----------[Development Journal]
Great functions man. Thanks ALOT, now I don''t have to spend weeks working out how to do this.

This topic is closed to new replies.

Advertisement