Cant see things

Here is my code, the purple line strip appears for a few millis, enough for me to se it flicker then the screen is black. If I remove the triangle and quad, I see a pruple line strip.

 private static void render() {
       GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);
        // TODO: all your rendering goes here
    int width = 200;
    int height = 25;
    int x = (Window.getWidth() - width) / 2;
    int y = Window.getHeight() - height - 50;

        GL11.glBegin(GL11.GL_LINE_STRIP);
        {
          GL11.glColor3f(0.4f, 0.0f, 0.7f);
          GL11.glVertex2i(x - 1, y);
          GL11.glVertex2i(x + width, y);
          GL11.glVertex2i(x + width, y + height + 1);
          GL11.glVertex2i(x - 1, y + height + 1);
          GL11.glVertex2i(x - 1, y);
        }
        GL11.glEnd();
        
        
            //GL11.glLoadIdentity();                                          // Reset The Current Modelview Matrix

            GL11.glTranslatef(-1.5f,0.0f,-1.0f);                        // Move Left 1.5 Units And Into The Screen 6.0
            GL11.glBegin(GL11.GL_TRIANGLES);                              // Drawing Using Triangles
                  GL11.glColor3f(1.0f,0.0f,0.0f);                        // Set The Color To Red
                  GL11.glVertex3f( 0.0f, 1.0f, 0.0f);                  // Move Up One Unit From Center (Top Point)
                  GL11.glColor3f(0.0f,1.0f,0.0f);                        // Set The Color To Green
                  GL11.glVertex3f(-3.0f,-1.0f, 0.0f);                  // Left And Down One Unit (Bottom Left)
                  GL11.glColor3f(0.0f,0.0f,1.0f);                        // Set The Color To Blue
                  GL11.glVertex3f( 1.0f,-1.0f, 0.0f);                  // Right And Down One Unit (Bottom Right)
            GL11.glEnd();                                                            // Finished Drawing The Triangle

            GL11.glTranslatef(3.0f,0.0f,0.0f);                        // Move Right 3 Units
            GL11.glColor3f(0.5f,0.5f,1.0f);                              // Set The Color To Blue One Time Only
            GL11.glBegin(GL11.GL_QUADS);                                    // Draw A Quad
                  GL11.glVertex3f(-1.0f, 1.0f, 0.0f);                  // Top Left
                  GL11.glVertex3f( 1.0f, 1.0f, 0.0f);                  // Top Right
                  GL11.glVertex3f( 1.0f,-1.0f, 0.0f);                  // Bottom Right
                  GL11.glVertex3f(-1.0f,-1.0f, 0.0f);                  // Bottom Left
            GL11.glEnd();      
                                                                  // Done Drawing The Quad
 }

I think you should call glPushMatrix() after glClear() and add the corresponding glPopMatrix() at the end of your render method.

Right now your are appending translations to your model-view matrix without removing them, which causes your drawing to “leave” the viewport.

thanks! gave that a whirl and my line_srip is now always visible, but nothing wlse. I pasted in code from the nehetutorial into the game loop in the clubies section.

Is there another method where you setup the “camera” ? It is usually done in a ‘reshape’ or ‘init’ callback and should contain stuff like glViewport(), gluPerspective() or glOrtho()…

Just a wild guess though : there seems to be a huge difference between line strip coordinates and other primitives. You could try to draw your quad using x and y vars, and see if it’s visible. :slight_smile:

ok, I can see things now by using the following code, I have no viewport or camera of any type set. I need to now find out what all the OpenGL call do and mean. :slight_smile:

       GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT); 
        // TODO: all your rendering goes here 
  
    int width = 200;
    int height = 25;
    int x = (Window.getWidth() - width) / 2;
    int y = Window.getHeight() - height - 50;
        GL11.glBegin(GL11.GL_LINE_STRIP);
        {
          GL11.glColor3f(0.0f, 0.9f, 0.0f);
          GL11.glVertex2i(x - 1, y);
          GL11.glVertex2i(x + width, y);
          GL11.glVertex2i(x + width, y + height + 1);
          GL11.glVertex2i(x - 1, y + height + 1);
          GL11.glVertex2i(x - 1, y);
        }
        GL11.glEnd();
  
  
  GL11.glBegin(GL11.GL_QUADS); 

   GL11.glTexCoord2f(0.0f, 0.0f); 
   GL11.glVertex3f(-width/2, -width/2, 0.0f); 

   GL11.glTexCoord2f(0.0f, 1.0f); 
   GL11.glVertex3f(-width/2, width/2, 0.0f); 

   GL11.glTexCoord2f(1.0f, 1.0f); 
   GL11.glVertex3f(width/2, width/2, 0.0f); 

   GL11.glTexCoord2f(1.0f, 0.0f); 
   GL11.glVertex3f(width/2, -width/2, 0.0f); 

   GL11.glEnd(); 
 
       //GL11.glMatrixMode(GL11.GL_MODELVIEW); 
      //GL11.glLoadIdentity(); 
      //GL11.glTranslatef(x, y, 0.0f); 
      //GL11.glRotatef(0.2f, 0.0f, 1.0f, 0.0f);
      
      // my first triangle
      GL11.glBegin(GL11.GL_TRIANGLES);
      GL11.glColor3f(1.0f, 0.0f, 0.0f);
            GL11.glVertex3f(x-50,x,0);
            GL11.glVertex3f(x-100,0,0);
            GL11.glVertex3f(x+100,0,0);
      GL11.glEnd(); 

[quote]ok, I can see things now by using the following code, I have no viewport or camera of any type set. I need to now find out what all the OpenGL call do and mean. :slight_smile:
[/quote]
Then you definitely need the Redbook. :wink:

IMHO OpenGL is not the kind of API you can master just by playing a bit with a piece of code. You need to understand what goes under, both the math and the core calls. Either read some detailed tutorial or a book (the Redbook can be found online), every hours you spent on it will pay. ;D

Although we helpfully set up GL when the window is created to a convenient 1:1 orthographic projection mode so stuff “just works” when you’re starting out :wink:

Cas :slight_smile:

That postion would put x=0, y=0, z=0= in the lower left corner with positive x to the right, positive y going up and positive z coming out of the glass towards the user. right?

If I can learn this, I may convert GT6 to LWJGL. …and possibly 3d, but don’t hold your breath :slight_smile: