OpenGL with Frame acting weird. Can someone please look over code.

Hello. I am practicing with openGL some more, before i even start a new project and I am having this slight problem with openGl drawing to a canvas with in a frame. It draws blue(since thats the color I picked) every where and even on the frame’s border. And on my Command Prompt if I move it over it.

Maybe someone could look over my source code(Remember this is just practice code so ignore the uglyness) and see if I am doing something wrong.

I used these when I did it.
Java SDK/JDK = jdk1.5.0_06
Java Run Time= jre1.5.0_06
JOGL Version =JSR-231 beta 02 - January 4

Thanks In advanced.


import java.awt.*;
import javax.media.opengl.*;
import javax.swing.*;


public class test{

private int checkC = 0;

private AWTGraphicsDevice GLGD;
private AWTGraphicsConfiguration GLGC;
private GLDrawable GLDraw;
private GL mainGL;
private GLCapabilities GLCap;
private GLContext GLCon;
private Graphics2D g2d;
private GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
private Canvas mainC;

private Frame frmTest = new Frame("Test");


public void setup(){
GLCap = new GLCapabilities();
GLCap.setDoubleBuffered(false);
GLCap.setSampleBuffers(false);
GLCap.setHardwareAccelerated(false);
GLCap.setRedBits(8);
GLCap.setBlueBits(8);
GLCap.setGreenBits(8);
GLCap.setAlphaBits(8);
//GLGD = new AWTGraphicsDevice(env.getDefaultScreenDevice());
//GLGC=(AWTGraphicsConfiguration)GLDrawableFactory.getFactory().chooseGraphicsConfiguration(GLCap,null,GLGD);

mainC = new Canvas();

GLDraw =GLDrawableFactory.getFactory().getGLDrawable(mainC,GLCap,null);
GLDraw.setSize(640,480);

mainC.setIgnoreRepaint(true);

GLCon = GLDraw.createContext(null);
GLCon.setSynchronized(true);

if (GLContext.getCurrent()==null){
System.out.println("Nothing is Current");
}else{
GLContext.getCurrent().release();
System.out.println("Whatever was current is Released");
}//END IF/ELSE STATEMENT


frmTest.setVisible(true);
frmTest.setIgnoreRepaint(true);
frmTest.setSize(640,480);
mainC.setVisible(true);
frmTest.add(mainC);
frmTest.setResizable(false);


mainC.addNotify();

GLDraw.setRealized(true);

checkC=GLCon.makeCurrent();

if (checkC == GLContext.CONTEXT_NOT_CURRENT)
System.out.println("NOT CURRENT");
else if (checkC == GLContext.CONTEXT_CURRENT_NEW)
System.out.println("NEW CURRENT");
else if (checkC == GLContext.CONTEXT_CURRENT)
System.out.println("Context Current");


loopmain();
}//END METHOD




public void loopmain(){

mainGL = GLCon.getGL();


mainGL.glClearColor(0.0f,.05f,.75f,1.0f);

mainGL.glViewport(0,0,640,480);

mainGL.glMatrixMode(mainGL.GL_PROJECTION);
mainGL.glLoadIdentity();
mainGL.glOrtho((double)0,(double)640,(double)0,(double)480,(double)0,(double)1);

mainGL.glDisable(mainGL.GL_DEPTH_TEST);
mainGL.glColor3f(1.0f,0f,0f);


while(true){
mainGL = GLCon.getGL();

mainGL.glClear(mainGL.GL_COLOR_BUFFER_BIT);

mainGL.glBegin(mainGL.GL_POINTS);
for (int a=0;a<40;a++)
mainGL.glVertex2i(320,a+50);

mainGL.glEnd();

mainGL.glFlush();
}//end while

}//END METHOD




public static void main(String args[]){
new test().setup();

}//END METHOD




}//END CLASS


This looks very odd. You are treating JOGL like it’s C, but in Java you have a threaded implementation, with an animator to run through the frames. I’m not saying this won’t work, maybe this is what all the gamers do, but if so it’s new to me.

For Some reason it works with Double Buffer, but not Single Buffer. Weird. When I turn Double Buffer on and get rid of flush and switch it with the GLDrawable swapbufffer() method It seems to my eyes work fine( That is until I minimize it, but I fixed that for I can). Also it goes real slow with lag when I move the window around if I dont use the java2d opengl pipeline. (-Dsun.java2d.opengl=true). mmmmmmmmmm


weirdest piece of code i’ve seen. don’t make sense to me. i think when u use gl with Canvas u need to override its paint method and make the context current from there and draw and swap buffer. that might explained why u may seen the result in double buffered mode. try looking into the demo package’s source (DualContext). u are trying to draw onto the Canvas, right?