Question
CREATE A JAVA PONG GAME USING THIS GL TEMPLATE, MUST BE IN THIS FORMAT. PLEASE MAKE IT SO ALL I HAVE TO DO IS COPY
CREATE A JAVA PONG GAME USING THIS GL TEMPLATE, MUST BE IN THIS FORMAT. PLEASE MAKE IT SO ALL I HAVE TO DO IS COPY AND PASTE IT INTO JGRASP TO RUN IT. DOESNT HAVE TO BE FANCY JUST HAS TO RUN.
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.*;
import javax.media.opengl.awt.GLCanvas;
import com.jogamp.opengl.util.*;
import com.jogamp.opengl.util.gl2.GLUT;
import javax.media.opengl.glu.*;
import java.util.Random;
import java.lang.Math;
import com.jogamp.opengl.util.texture.*;
import java.io.*;
public class templateForProject implements GLEventListener
{
// include public static void main to run it
public static void main(String[] arg){
GLProfile glp = GLProfile.getDefault();
GLCapabilities caps = new GLCapabilities(glp);
GLCanvas canvas = new GLCanvas(caps);
Frame frame = new Frame("AWT Window Test");
frame.setSize(300, 300);
frame.add(canvas);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
templateForProject mp = new templateForProject();
canvas.addGLEventListener(mp);
Animator animator = new Animator(canvas);
animator.add(canvas);
animator.start();
}
//To implement GLEventListener, one
// must tell what to do inside
// four methods listed below.
public void display(GLAutoDrawable drawable){
GL2 gl = drawable.getGL().getGL2();
//gl.glClearColor(255.0f/255, 153.0f/255,153.0f/255,0);
gl.glClearColor(0,0,0,0);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
// Provide your drawing here
// either by code
// or by function call
}
public void dispose(GLAutoDrawable drawable){
// provide your response. For now, leave it empty
}
public void init(GLAutoDrawable drawable){
GL2 gl = drawable.getGL().getGL2();
// provide your response
}
public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h){
GL2 gl = drawable.getGL().getGL2();
// provide your response
}
}
Step 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