Advertisement

OpenGL and Java

Started by March 21, 2006 10:49 PM
1 comment, last by pseudosig 18 years, 6 months ago
I'm having issues trying to get colors show up on a drawn triangle in a Java program using OpenGL via JOGL. In comparing my code to lesson 3 on this website, I can't find the problem. The triange is drawn, but the color doesn't show up. Are there possible flags or conflicts which would stop rendering color? Thanks in advanced! Here's my code (Note, gl is the GL object, and it's global in my class).

gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();

glu.gluLookAt(xPlayer, yPlayer, zPlayer, xLookAt, yLookAt, zLookAt, 0, 1, 0); // position camera
drawTriangle();

...
...
...

private void drawTriangle() 
{
     gl.glBegin(GL.GL_TRIANGLES); // Drawing Using Triangles

     gl.glColor3f(1.0f, 0.0f, 0.0f);
     gl.glVertex3f(0.0f, 5.0f, 3.0f); // Top

     gl.glColor3f(0.0f, 1.0f, 0.0f);
     gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left

     gl.glColor3f(0.0f, 0.0f, 1.0f);
     gl.glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right

     gl.glEnd();
}
gl.glEnable (GL_COLOR_MATERIAL)
drawTriangle()
gl.glDisable (GL_COLOR_MATERIAL)

You could also use glMaterial/glColorMaterial instead of glColor, then your lighting will work, too.
Thanks
Advertisement
Quote: Original post by Dani008
gl.glEnable (GL_COLOR_MATERIAL)
drawTriangle()
gl.glDisable (GL_COLOR_MATERIAL)

You could also use glMaterial/glColorMaterial instead of glColor, then your lighting will work, too.


Okay, that worked. Thanks. How did you know, or where is it documented when you need to use that?

This topic is closed to new replies.

Advertisement