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