i have created a “Frame”, and then added a “GLCanvas”
to it.
In the GLCanvas, i tried to draw a “TRIANGLES” with the
following code:
gl.glBegin(GL.GL_TRIANGLES);
gl.glVertex3f(0.0f, 0.0f, 0.0f);
gl.glVertex3f(1.0f, 0.0f, 0.0f);
gl.glVertex3f(1.0f, 1.0f, 0.0f);
gl.glEnd();
But the parameters: “0.0f” and “1.0f” seem to be relative to
the Frame width and height. And the Frame’s left top corner is
always (-0.1f,-0.1f), left bottom corner (-0.1f,0.1f) and so on.
What should i do to create a TRIANGLE with absolute values?
(not dependent on Frame height, width)
Thanx.
hier is the complete code:
import net.java.games.jogl.GLEventListener;
import net.java.games.jogl.GL;
import net.java.games.jogl.GLDrawable;
import net.java.games.jogl.DebugGL;
public class c_renderer implements GLEventListener {
private GL gl;
private GLDrawable glDrawable;
public void init(GLDrawable drawable) {
this.gl = drawable.getGL();
this.glDrawable = drawable;
drawable.setGL(new DebugGL(drawable.getGL()));
System.out.println("Init GL is " + gl.getClass().getName());
}
public void display(GLDrawable drawable) {
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glColor3f(1.0f, 0.0f, 0.0f);
gl.glBegin(GL.GL_TRIANGLES);
gl.glVertex3f(0.0f, 0.0f, 0.0f);
gl.glVertex3f(1.0f, 0.0f, 0.0f);
gl.glVertex3f(1.0f, 1.0f, 0.0f);
gl.glEnd();
gl.glBegin(GL.GL_QUADS);
gl.glVertex3f(-0.1f, 0.1f, 0.0f);
gl.glVertex3f(0.1f, 0.1f, 0.0f);
gl.glVertex3f(0.1f, -0.1f, 0.0f);
gl.glVertex3f(-0.1f, -0.1f, 0.0f);
gl.glEnd();
}
public void reshape(
GLDrawable drawable,
int x,
int y,
int width,
int height) {
}
public void displayChanged(
GLDrawable drawable,
boolean modeChanged,
boolean deviceChanged) {
}
}
//*********************************************
import net.java.games.jogl.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class c_openGL_test {
public static void main(String[] args) {
try {
Frame testFrame = new Frame(“TestFrame”);
testFrame.setSize(200, 200);
GLCapabilities glCaps = new GLCapabilities();
glCaps.setRedBits(8);
glCaps.setBlueBits(8);
glCaps.setGreenBits(8);
glCaps.setAlphaBits(8);
GLCanvas canvas =
GLDrawableFactory.getFactory().createGLCanvas(glCaps);
canvas.setSize(400, 400);
testFrame.add(canvas);
canvas.addGLEventListener(new c_renderer());
final Animator animator = new Animator(canvas);
testFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
animator.stop();
System.exit(0);
}
});
testFrame.show();
animator.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}