0% found this document useful (0 votes)
13 views

New Text Document

The document defines a Java class that implements the GLEventListener interface. The class contains methods for initializing OpenGL, disposing resources, displaying graphics, and handling viewport resizing. It renders a teapot using OpenGL.

Uploaded by

simontarrazi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

New Text Document

The document defines a Java class that implements the GLEventListener interface. The class contains methods for initializing OpenGL, disposing resources, displaying graphics, and handling viewport resizing. It renders a teapot using OpenGL.

Uploaded by

simontarrazi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

package tp;

import com.jogamp.opengl.util.gl2.GLUT;

import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
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 java.awt.BorderLayout;
import javax.media.opengl.glu.GLU;
import javax.swing.JFrame;

public class tp1 implements GLEventListener {

public static void main(String[] args) {


tp1 tp1 = new tp1();
}
public tp1() {
GLProfile profile = GLProfile.getDefault();
GLCapabilities capabilities = new GLCapabilities(profile);
GLCanvas canvas = new GLCanvas(capabilities);
canvas.addGLEventListener(this);

JFrame frame = new JFrame("I3333 lab 1");


frame.getContentPane().add(canvas, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(512, 512);
frame.setVisible(true);

@Override
public void init(GLAutoDrawable glAutoDrawable) {

@Override
public void dispose(GLAutoDrawable glAutoDrawable) {

@Override
public void display(GLAutoDrawable glAutoDrawable) {
GL2 gl= glAutoDrawable.getGL().getGL2();
gl.glClearColor(0 ,0,0,0);
gl.glClear(GL2.GL_COLOR_BUFFER_BIT);

gl.glPolygonMode(GL2.GL_FRONT_AND_BACK,GL2.GL_LINE);

gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glTranslated(0,0,-3);
gl.glRotated(60,0,1,0);
gl.glColor3f(1f,1f,0);
GLUT glut = new GLUT();

glut.glutSolidTeapot(1);

@Override
public void reshape(GLAutoDrawable glAutoDrawable, int x, int y, int w, int h)
{
GL2 gl= glAutoDrawable.getGL().getGL2();
gl.glViewport(0,0,w/2,h/2);

gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();

GLU glu = new GLU();


glu.gluPerspective(60,1,2,100);
}
}

You might also like