LWJGL Forum

Programming => OpenGL => Topic started by: ibelieve on February 24, 2006, 10:15:11

Title: Basic OpenGL Rendering using LWJGL can't see a 3Dcube...
Post by: ibelieve on February 24, 2006, 10:15:11
hi everybody i used your source Basic "OpenGL Rendering using LWJGL" to start opengl under java....
it 's useful but i had some problems when i made some changes...
in fact i want to make a cube but it doesn t work well, when i modify the gluLookAt parameters, i only see lines but not faces of my cube...
could you help me ?

that's my render

/**
  * Render the current frame
  */
 private static void render() {
   // clear the screen
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
   GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

   // center square according to screen size
   GL11.glPushMatrix();
   GL11.glTranslatef(Display.getDisplayMode().getWidth() / 2, Display.getDisplayMode().getHeight() / 2, 0.0f);

     // rotate square according to angle
    GL11.glRotatef(angle, 0, 0, 1.0f);

     // render the square
   
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GLU.gluLookAt(1,1,1,0,0,0,1,1,0);
     
     GL11.glBegin(GL11.GL_QUADS);

   
     GL11.glColor3d(1,0,0);
     GL11.glVertex3i(50,50,50);
     GL11.glVertex3i(50,-50,50);
     GL11.glVertex3i(-50,-50,50);
     GL11.glVertex3i(-50,50,50);
      //1 face
     
     GL11.glColor3d(0,1,0);
     GL11.glVertex3i(50,50,-50);
     GL11.glVertex3i(50,-50,-50);
     GL11.glVertex3i(-50,-50,-50);
     GL11.glVertex3i(-50,50,-50);
      //2 faces

     GL11.glColor3d(0,0,1);
     GL11.glVertex3i(50,50,50);
     GL11.glVertex3i(50,-50,50);
     GL11.glVertex3i(50,-50,-50);
     GL11.glVertex3i(50,50,-50);
      //3 faces
     
     GL11.glColor3d(0,1,1);
     GL11.glVertex3i(-50,50,50);
     GL11.glVertex3i(-50,-50,50);
     GL11.glVertex3i(-50,-50,-50);
     GL11.glVertex3i(-50,50,-50);
      //4 faces

     GL11.glColor3d(1,0,0);
     GL11.glVertex3i(-50,50,-50);
     GL11.glVertex3i(-50,50,50);
     GL11.glVertex3i(50,50,50);
     GL11.glVertex3i(50,50,-50);
      //5 faces

     GL11.glColor3d(1,1,0);
     GL11.glVertex3i(-50,-50,-50);
     GL11.glVertex3i(-50,-50,50);
     GL11.glVertex3i(50,-50,50);
     GL11.glVertex3i(50,-50,-50);

     GL11.glEnd();

   GL11.glPopMatrix();
 }


maybe bad parameters in vertex ? or lookat ?
thanks
Title: Basic OpenGL Rendering using LWJGL can't see a 3Dcube...
Post by: mark on February 24, 2006, 13:49:54
I'm a bit inexperienced myself, but you could try setting

GL11.glPolygonMode(GL11.GL_FRONT,GL11.GL_FILL);

before glBegin. That's the best I can think of.
Title: hmmmmm...
Post by: Fool Running on February 24, 2006, 14:30:12
Try putting the code
     // render the square
 
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GLU.gluLookAt(1,1,1,0,0,0,1,1,0);

in between the
   GL11.glPushMatrix();
   GL11.glTranslatef(Display.getDisplayMode().getWidth() / 2, Display.getDisplayMode().getHeight() / 2, 0.0f);

and look at the parameters for GLU.gluLookAt()... I think you have some parameters NOT what you want them to be.
(Don't try this if Mark's suggestion works :lol: )
Title: Basic OpenGL Rendering using LWJGL can't see a 3Dcube...
Post by: ibelieve on February 24, 2006, 15:17:20
thanks but it doen t work...
in fact i try this

GLU.gluPerspective(5f,1f,1f,50f);
instead of glulookat


and it is better...
Title: hmmmmm....
Post by: Fool Running on February 27, 2006, 00:54:44
Ok... I think I got something (now that I actually tried it :lol: )
change:// center square according to screen size
   GL11.glPushMatrix();
   GL11.glTranslatef(Display.getDisplayMode().getWidth() / 2, Display.getDisplayMode().getHeight() / 2, 0.0f);

     // rotate square according to angle
    GL11.glRotatef(angle, 0, 0, 1.0f);

     // render the square
 
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GLU.gluLookAt(1,1,1,0,0,0,1,1,0);

to
       GL11.glMatrixMode(GL_PROJECTION);
       GL11.glLoadIdentity();
       GLU.gluPerspective(45.0f, 1f, 1f, 5000f);
       GL11.glMatrixMode(GL11.GL_MODELVIEW);
       
       GL11.glLoadIdentity();
       
       GL11.glPushMatrix();
       GLU.gluLookAt(0, 0, -1000, 0, 0, 0, 0, 1, 0);

       // rotate square according to angle
       GL11.glRotatef(angle, 0, 0, 1.0f);

I think that should get you started :D
Title: Basic OpenGL Rendering using LWJGL can't see a 3Dcube...
Post by: darkprophet on February 27, 2006, 01:22:27

       GL11.glMatrixMode(GL_PROJECTION);
       GL11.glLoadIdentity();
       GLU.gluPerspective(45.0f, 1f, 1f, 5000f);
       GL11.glMatrixMode(GL11.GL_MODELVIEW);
       
       GL11.glLoadIdentity();
       
       GL11.glPushMatrix();
       GLU.gluLookAt(0, 0, -1000, 0, 0, 0, 0, 1, 0);

       // rotate square according to angle
       GL11.glRotatef(angle, 0, 0, 1.0f);


You dont need that glPushMatrix in that code. In fact, im surprised it even ran because the stack is incomplete when you switch buffers

DP
Title: hmmmmmm...
Post by: Fool Running on February 27, 2006, 14:31:12
Its needed because there is a popMatrix() at the end. But, yes, its not really needed unless he starts adding other stuff besides a cube.
Title: Basic OpenGL Rendering using LWJGL can't see a 3Dcube...
Post by: ibelieve on February 27, 2006, 15:29:11
thanks it is great
I've just made changes in function glulookat (put a value in first parameters)

GLU.gluLookAt(10, 0, -10, 0, 0, 0, 0, 1, 0);

so we have a great cube now :D
thanks to all
i ll put the source when i finished it, but first i want to change colors when i made a click with my mouse...lol
[/code]