mirror of
https://github.com/Cpt-Adok/SNAKE.git
synced 2026-01-25 06:34:06 +00:00
add graphics buffers
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
.DS_Store
|
||||
*.class
|
||||
|
||||
BIN
src/Main.class
BIN
src/Main.class
Binary file not shown.
@@ -15,7 +15,6 @@ import static org.lwjgl.opengl.GL11.*;
|
||||
import static org.lwjgl.system.MemoryStack.*;
|
||||
import static org.lwjgl.system.MemoryUtil.*;
|
||||
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
if(!GLFW.glfwInit()) {
|
||||
|
||||
@@ -1,5 +1,27 @@
|
||||
package graphics;
|
||||
|
||||
public class EBO {
|
||||
import org.lwjgl.opengl.GL15;
|
||||
|
||||
public class EBO {
|
||||
private int id;
|
||||
|
||||
public EBO(int[] indices) {
|
||||
this.id = GL15.glGenBuffers();
|
||||
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, this.id);
|
||||
GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STATIC_DRAW);
|
||||
bind();
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
unbind();
|
||||
GL15.glDeleteBuffers(this.id);
|
||||
}
|
||||
|
||||
public void bind() {
|
||||
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, (int)this.id);
|
||||
}
|
||||
|
||||
public void unbind() {
|
||||
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,46 @@
|
||||
package graphics;
|
||||
|
||||
public class VAO {
|
||||
import static org.lwjgl.opengl.GL11.glDrawArrays;
|
||||
import static org.lwjgl.opengl.GL11.glDrawElements;
|
||||
|
||||
import org.lwjgl.opengl.GL30;
|
||||
|
||||
public class VAO {
|
||||
private int id;
|
||||
|
||||
public VAO() {
|
||||
this.id = GL30.glGenVertexArrays();
|
||||
bind();
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
unbind();
|
||||
GL30.glDeleteVertexArrays(id);
|
||||
}
|
||||
|
||||
public void bind() {
|
||||
GL30.glBindVertexArray(this.id);
|
||||
}
|
||||
|
||||
public void unbind() {
|
||||
GL30.glBindVertexArray(0);
|
||||
}
|
||||
|
||||
public void setAttributePointer(int index, int size, int type, int stride, long offset) {
|
||||
GL30.glEnableVertexAttribArray(index);
|
||||
GL30.glVertexAttribPointer(index, size, type, false, stride, offset);
|
||||
}
|
||||
|
||||
public void drawElement(int mode, int count, int type, long indices) {
|
||||
bind();
|
||||
|
||||
glDrawElements(mode, count, type, indices);
|
||||
unbind();
|
||||
}
|
||||
|
||||
public void drawElementIndices(int mode, int first, int count) {
|
||||
bind();
|
||||
glDrawArrays(mode, first, count);
|
||||
unbind();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,28 @@
|
||||
package graphics;
|
||||
|
||||
public class VBO {
|
||||
import org.lwjgl.opengl.GL15;
|
||||
|
||||
public class VBO {
|
||||
private int id;
|
||||
|
||||
public VBO(float[] vertices) {
|
||||
this.id = GL15.glGenBuffers();
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.id);
|
||||
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STATIC_DRAW);
|
||||
|
||||
bind();
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
unbind();
|
||||
GL15.glDeleteBuffers(this.id);
|
||||
}
|
||||
|
||||
public void bind() {
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.id);
|
||||
}
|
||||
|
||||
public void unbind() {
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user