Is anyone familiar with GL4Java? If so I have a problem I could really use some assistance with. I’m trying to do something as basic as rendering a polygon, however, when I run I am unable to see object just black background. Also I have a menu bar (through SWING) at the top of the frame and it click on certains items the list is hidden behind the black canvas. Can anyone assist. Below is my code for the polygon
import gl4java.GLContext;
import gl4java.awt.GLAnimCanvas;
public class gci_glcode extends GLAnimCanvas {
public gci_glcode(int w, int h) {
super(w,h);
}
public void preInit()
{
doubleBuffer = true;
stereoView = false; // buffering but not stereoview
}
public void init(){
float width = (float)getSize().width;
float height = (float)getSize().height;
gl.glShadeModel(GL_SMOOTH); gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //This Will Clear The Background Color To Black
gl.glClearDepth(1.0); //Enables Clearing Of The Depth Buffer
gl.glEnable(GL_DEPTH_TEST); //Enables Depth Testing
gl.glDepthFunc(GL_LEQUAL); //The Type Of Depth Test To Do
gl.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective
/*qobj = (int)glu.gluNewQuadric();
glu.gluQuadricNormals(qobj, GLU_SMOOTH); // Create Smooth Normals ( NEW )
glu.gluQuadricTexture(qobj, GL_TRUE);*/
}
public void doCleanup(){
stop();
}
public void reshape(int width, int height){
//Reset The Current Viewport And Perspective Transformation
System.out.println("Width : "+width+" Height: "+height);
if(height==0)height=1;
gl.glViewport(0, 0, width, height); // Reset The Current Viewport And Perspective Transformation
gl.glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
gl.glLoadIdentity(); // Reset The Projection Matrix
glu.gluPerspective(45.0f, width / height, 0.1f, 100.0f); // Calculate The Aspect Ratio Of The Window
gl.glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
gl.glLoadIdentity(); // Reset The ModalView Matrix
}
public void display(){
/*if(!cvsIsInit() | | !glj.gljMakeCurrent())
{
System.out.println(“The program is broken; didn’t initialize”);
}*/
if(glj.gljMakeCurrent()== false) return;
gl.glMatrixMode(GL_MODELVIEW);
gl.glLoadIdentity();
gl.glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
/*gl.glPushMatrix();
gl.glTranslated(-100,0,0);
glu.gluSphere(qobj, 20,20,20);
gl.glPopMatrix();
gl.glFlush();*/
gl.glClearColor(0.0f,0.0f,0.0f,0.0f);
gl.glClear(GL_COLOR_BUFFER_BIT);
gl.glColor3f(1.0f,1.0f,1.0f);
gl.glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
gl.glBegin(GL_POLYGON);
gl.glVertex3f(-1.0f,1.0f,0.0f);
gl.glVertex3f(1.0f,1.0f,0.0f);
gl.glVertex3f(1.0f,-1.0f,0.0f);
gl.glVertex3f(-1.0f,-1.0f,0.0f);
gl.glEnd();
gl.glFlush();
glj.gljSwap(); //Swap buffers
glj.gljFree(); // release GL
}
}