Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import java.nio.FloatBuffer;
- import org.lwjgl.opengl.GL15;
- import static org.lwjgl.glfw.GLFW.*;
- import static org.lwjgl.opengl.GL.*;
- import static org.lwjgl.opengl.GL11.*;
- import static org.lwjgl.opengl.GL15.*;
- import static org.lwjgl.opengl.GL20.glEnableVertexAttribArray;
- import static org.lwjgl.opengl.GL20.glVertexAttribPointer;
- import static org.lwjgl.opengl.GL30.glBindVertexArray;
- import static org.lwjgl.opengl.GL30.glGenVertexArrays;
- import static org.lwjgl.system.MemoryUtil.*;
- import static org.lwjgl.system.MemoryStack.*;
- public class TestGLFWCore {
- public static void main(String[] args) {
- // Initialize GLFW
- glfwInit();
- // Create window
- glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
- glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
- glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
- long window = glfwCreateWindow(800, 600, "OpenGL 3.2 Core Window", NULL, NULL);
- glfwMakeContextCurrent(window);
- createCapabilities();
- // Setup geometry
- int size = 2;
- int verts = 3;
- int bytes = 4;
- int vbo;
- int vao;
- stackPush();
- {
- // Initial vertex data
- FloatBuffer buffer = stackMallocFloat(verts * size);
- buffer.put(-0.5f).put(-0.5f); // Vert 1
- buffer.put(+0.5f).put(-0.5f); // Vert 2
- buffer.put(+0.0f).put(+0.5f); // Vert 3
- buffer.flip();
- // Generate buffers
- vbo = glGenBuffers();
- vao = glGenVertexArrays();
- // Upload Vertex Buffer
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
- glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
- glBindVertexArray(vao);
- // Set attributes
- glEnableVertexAttribArray(0);
- glVertexAttribPointer( 0, size, GL_FLOAT, false, size*bytes, 0 );
- // Unbind
- glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
- glBindVertexArray(0);
- }
- stackPop();
- // Game loop
- while (!glfwWindowShouldClose(window)) {
- // Poll
- glfwPollEvents();
- // Bind
- glBindVertexArray(vao);
- // Draw
- glDrawArrays(GL_TRIANGLES, 0, verts);
- // Blit
- glfwSwapBuffers(window);
- }
- // Terminate
- glfwTerminate();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement