Drawing a Quad

Suppose I want to draw a quad on the screen using
LWJGL.

Form pixel locaion (200,200) to pixel location (400,400)

how do I do that?

If I understand your question, you want to draw a 2D quad.
First you should turn OpenGL view mode into Ortho mode (2D), and then draw the quad using something like :


glBegin(GL_QUADS);
   glVertex2i(200,200);
   glVertex2i(400,200);
   glVertex2i(400,400);
   glVertex2i(200,400);
glEnd();

…in the rendering loop.

You should take a look at Nehe’s tutorials (look at the LWJGL ports down the “First Polygon” tutorial page).

Chman

Doesn’t LWJGL setup an ortho view for you as a default now? With one pixel to one openGL unit, just how you’re after.

…and you might want to add a glColor3f(r, g, b) in there as well.

All the Nehe Tutorials seem to draw the quads using

GL11.glVertex3f

Hmm, I can’t seem to get it working…

I’m doing


      public void render()
      {
            GL11.glLoadIdentity();                                              // Reset The View
            GL11.glOrtho(0, 640, 0, 480, -1, 1);
            draw2DQuad(0,0,200,200);
      }

      private void draw2DQuad(int x1, int y1, int x2, int y2)
      {
            GL11.glBegin(GL11.GL_QUADS);
                  GL11.glTexCoord2f(0.0f, 1.0f);                                      // First Texture Coord
                  GL11.glVertex2i(x1,y1);
                  
                  GL11.glTexCoord2f(1.0f, 1.0f);                                      // Second Texture Coord
                  GL11.glVertex2i(x2,y1);
                  
                  GL11.glTexCoord2f(1.0f, 0.0f);                                      // Third Texture Coord
                  GL11.glVertex2i(x2,y2);
                  
                  GL11.glTexCoord2f(0.0f, 0.0f);                                      // Fourth Texture Coord
                  GL11.glVertex2i(x1,y2);
            GL11.glEnd();             
      }

If I do a


GL11.glTranslatef(0.0f, 0.0f, -2.0f);

after the glLoadIdentity, I can see the
quad on the screen, but not a the location where
I specified it do be…

:’(

This is what I use for JOGL:

you would use code like the following to make sure you are using an orthagonal setup:

the above code should be placed inside your reshape method so that you can draw a quad using the following at your intended location (placed inside your display method:

Spend some time looking at the nehe demos as people have pointed towards above this post. Lots of good stuff to be learnt there. :smiley:

edit - fixed some spellings. :slight_smile:

[quote]All the Nehe Tutorials seem to draw the quads using

GL11.glVertex3f
[/quote]
Lots of methods have slightly different names to indicate what parameters they take. 3f for three floats for example. Usually for ones that take less parameters (like 2i) the third one just ends up defaulting to 0, which is just fine for most 2d stuff.