Basic OpenGL Rendering using LWJGL can't see a 3Dcube...

Started by ibelieve, February 24, 2006, 10:15:11

Previous topic - Next topic

ibelieve

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

mark

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.

Fool Running

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: )
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

ibelieve

thanks but it doen t work...
in fact i try this
GLU.gluPerspective(5f,1f,1f,50f);
instead of glulookat


and it is better...

Fool Running

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
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

darkprophet

       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

Fool Running

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.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

ibelieve

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]