Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.jogamp.newt.event.WindowAdapter;
- import com.jogamp.newt.event.WindowEvent;
- import com.jogamp.newt.opengl.GLWindow;
- import com.jogamp.opengl.util.FPSAnimator;
- import java.nio.FloatBuffer;
- import javax.media.opengl.*;
- public class Main {
- static private class EventListener implements GLEventListener {
- float[] vertices = {
- -1.0f, -1.0f, 0.0f,
- 1.0f, -1.0f, 0.0f,
- 0.0f, 1.0f, 0.0f,
- };
- int[] vertexBuffer = new int[1];
- @Override
- public void init(GLAutoDrawable drawable) {
- GL3 gl = drawable.getGL().getGL3();
- gl.glGenBuffers(1, vertexBuffer, 0);
- gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, vertexBuffer[0]);
- gl.glBufferData(GL3.GL_ARRAY_BUFFER, vertices.length * 4, FloatBuffer.wrap(vertices), GL3.GL_STATIC_DRAW);
- gl.glClearColor(0, 0, 1.0f, 1.0f);
- }
- @Override
- public void dispose(GLAutoDrawable drawable) {
- GL3 gl = drawable.getGL().getGL3();
- gl.glDeleteBuffers(1, vertexBuffer, 0);
- }
- @Override
- public void display(GLAutoDrawable drawable) {
- GL3 gl = drawable.getGL().getGL3();
- gl.glClear(GL3.GL_COLOR_BUFFER_BIT | GL3.GL_DEPTH_BUFFER_BIT);
- gl.glEnableVertexAttribArray(0);
- gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, vertexBuffer[0]);
- gl.glVertexAttribPointer(
- 0,
- 3,
- GL3.GL_FLOAT,
- false,
- 0,
- 0
- );
- gl.glDrawArrays(GL3.GL_TRIANGLE_STRIP, 0, 3);
- gl.glDisableVertexAttribArray(0);
- }
- @Override
- public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
- }
- }
- public static void main(String[] args) {
- GLProfile profile = GLProfile.get(GLProfile.GL3);
- if(!GLProfile.isAvailable(GLProfile.GL3)) {
- System.out.println("No OpenGL 3");
- System.exit(1);
- }
- GLCapabilities caps = new GLCapabilities(profile);
- GLWindow window = GLWindow.create(caps);
- window.setSize(800, 600);
- window.setVisible(true);
- window.setTitle("Newt Window");
- window.addWindowListener(new WindowAdapter() {
- @Override
- public void windowDestroyNotify(WindowEvent arg0) {
- System.exit(0);
- }
- });
- window.addGLEventListener(new EventListener());
- FPSAnimator animator = new FPSAnimator(60);
- animator.add(window);
- animator.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment