Question
Can anyone help me please I tried search and watching videos on how to make it but I could not pls help pls This is
Can anyone help me please I tried search and watching videos on how to make it but I could not pls help pls
This is an important method which holds the code for developing graphics. This requires GLAutoDrawable interface object as parameter. In Display() method, initially get OpenGL context using object of GL interface (GL inherits GLBase interface which contains methods to generate all OpenGL context objects). Since this tutorial is about JOGL2 let us generate GL2 object. Let us go through code snippet for getting GL2 Object: //Generating GL object GL gl=drawable.getGL(); GL gl=drawable.getGL(); //Using this Getting the Gl2 Object //this can be written in a single line like final GL2 gl = drawable.getGL().getGL2(); Using the object of GL2 interface, one can access the members of GL2 interface, which in turn provide access to OpenGL [1.0... 3.0] functions. Drawing a line GL2 interface contains huge list of methods but here three main important methods are discussed namely glBegin(), glVertex(), and glEnd(). Sr. No. Methods and Description 1 glBegin() This method starts the process of drawing a line. It takes predefined string integer GL_LINES as a parameter, which is inherited from GL interface. 2 glVertex3f()/glVertex2f() This method creates the vertex and we have to pass coordinates as parameters 3f and 2f, which denote 3dimentional floating point coordinates and 2dimentional floating point coordinates respectively. 3 glEnd() ends the line Let us go through the program to draw a line: import javax.media.opengl.GL2; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLEventListener; import javax.media.opengl.GLProfile; import javax.media.opengl.awt.GLCanvas; import javax.swing.JFrame; public class Line implements GLEventListener{ @Override public void display(GLAutoDrawable drawable) { final GL2 gl = drawable.getGL().getGL2(); gl.glBegin (GL2.GL_LINES);//static field gl.glVertex3f(0.50f,-0.50f,0); gl.glVertex3f(- 0.50f,0.50f,0); gl.glEnd(); } @Override public void dispose(GLAutoDrawable arg0) { //method body } @Override public void init(GLAutoDrawable arg0) { // method body } @Override public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) { // method body } public static void main(String[] args) { //getting the capabilities object of GL2 profile final GLProfile profile = GLProfile.get(GLProfile.GL2); GLCapabilities capabilities = new GLCapabilities(profile); // The canvas final GLCanvas glcanvas = new GLCanvas(capabilities); Line l = new Line(); glcanvas.addGLEventListener(l); glcanvas.setSize(400, 400); //creating frame final JFrame frame = new JFrame ("straight Line"); //adding canvas to frame frame.getContentPane().add(glcanvas); frame.setSize(frame.getContentPane().getPreferredSize()); frame.setVisible(true); }//end of main }//end of classimport javax.media.opengl.GL2; Drawing shapes using GL_Lines Let us go through a program to draw a triangle using GL_LINES: import javax.media.opengl.GL2; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLEventListener; import javax.media.opengl.GLProfile; import javax.media.opengl.awt.GLCanvas; import javax.swing.JFrame; public class Triangle implements GLEventListener{ @Override public void display(GLAutoDrawable drawable) { final GL2 gl = drawable.getGL().getGL2(); gl.glBegin (GL2.GL_LINES); //drawing the base gl.glBegin (GL2.GL_LINES); gl.glVertex3f(-0.50f, -0.50f, 0); gl.glVertex3f(0.50f, -0.50f, 0); gl.glEnd(); //drawing the right edge gl.glBegin (GL2.GL_LINES); gl.glVertex3f(0f, 0.50f, 0); gl.glVertex3f(-0.50f, -0.50f, 0); gl.glEnd(); //drawing the lft edge gl.glBegin (GL2.GL_LINES); gl.glVertex3f(0f, 0.50f, 0); gl.glVertex3f(0.50f, -0.50f, 0); gl.glEnd(); gl.glFlush(); } @Override public void dispose(GLAutoDrawable arg0) { //method body } @Override public void init(GLAutoDrawable arg0) { // method body } @Override public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) { // method body } public static void main(String[] args) { //getting the capabilities object of GL2 profile final GLProfile profile = GLProfile.get(GLProfile.GL2); GLCapabilities capabilities = new GLCapabilities(profile); // The canvas final GLCanvas glcanvas = new GLCanvas(capabilities); Triangle l = new Triangle(); glcanvas.addGLEventListener(l); glcanvas.setSize(400, 400); //creating frame final JFrame frame = new JFrame ("Triangle"); //adding canvas to frame frame.getContentPane().add(glcanvas); frame.setSize(frame.getContentPane().getPreferredSize()); frame.setVisible(true); }//end of main }//end of classimport javax.media.opengl.GL2;
straight Line Drawing shapes using GL_Lines Let us go through a program to draw a triangle using GL LINES: import javax.media.opengl.GL2; import javax.media.opengi.GLAutoDrawable; import javax.media.opengi.GLCapabilities; import javax.media.opengi.GLEventListener; import javax.media.opengi.GLProfile; import javax.media.opengl.awt.GLCanvas; import javax.swing.JFrame; public class Triangle implements GLEventListener @Override public void display (GLAutoDrawable drawable) { final GL2 gl -drawable.getGL ().getGL2(); gl.glBegin (GL2.GL_LINES); //drawing the base straight Line Drawing shapes using GL_Lines Let us go through a program to draw a triangle using GL LINES: import javax.media.opengl.GL2; import javax.media.opengi.GLAutoDrawable; import javax.media.opengi.GLCapabilities; import javax.media.opengi.GLEventListener; import javax.media.opengi.GLProfile; import javax.media.opengl.awt.GLCanvas; import javax.swing.JFrame; public class Triangle implements GLEventListener @Override public void display (GLAutoDrawable drawable) { final GL2 gl -drawable.getGL ().getGL2(); gl.glBegin (GL2.GL_LINES); //drawing the baseStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started