This original from my c++ code was an inclass quiz…the java version I’m doing just for the heck of it. Not for a grade. Can someone point out what I need to do to
get display draw Triangle in a loop - should print the # of triangles specified by the variable “num”
thanks…Bernie
import javax.media.opengl.;
import javax.swing.;
public class Quiz1{
public static void main (String []args){
final int num = 1;
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame jframe = new JFrame(Quiz1.class.getSimpleName());
jframe.setSize(500,500);
jframe.setLocationRelativeTo(null);//center of screen
GLCanvas canvas = new GLCanvas();
canvas.addGLEventListener(new GLEventListener(){
public void init(GLAutoDrawable drawable){}
public void display(GLAutoDrawable drawable){
GL gl = drawable.getGL();
for (int i = 0; i< num; i++){
gl.glPushMatrix();
gl.glScalef(1/num,1/num,1);
gl.glTranslatef((1/num*i), 0, 0);
drawTriangle();
gl.glPopMatrix();
}
}
public void drawTriangle(){
gl.glClearColor(0.0f,0.0f,0.0f,0.0f);
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glColor3f(1.0f,1.0f,0.0f);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIsentity();
gl.glOrtho2D(0,1,0,1);
gl.glBegin(GL.GL_POLYGON);
gl.glVertex2f(0.0,0.0);
gl.glVertex2f(.5,1.0);
gl.glVertex2f(1.0,0.0);
gl.glEnd();
gl.glFlush();
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged){}
});
jframe.add(canvas);
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.setVisible(true);
}
}