LWJGL 3.1.6 crashes on Win 10 - java

even if this question was ask multiple times (i readed all of that and no solution worked for me), I am trying to model a rectangle with LWJGL and OpenGL
, but it crashes every time. Here my PC-Stats:
AMD-Ryzen 1600x |
MSI Nvidia GTX 1060 (6GB) |
MSI x370 Carbon Pro Motherboard
I also tried this on an Intel-Setup, with an i7 Processor and a Nvidia Quadro K 1000M setup, but same Error you can see in the following:
https://hastebin.com/ayiqiritov.makefile
My Drawing Method:
public void render(RawModel model){
GL30.glBindVertexArray(model.getVaoID());
GL20.glEnableVertexAttribArray(0);
GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, model.getVertexCount());
GL20.glDisableVertexAttribArray(0);
GL30.glBindVertexArray(0);
}
In this class I create VAOs and the VBOs and store data into those:
private List<Integer> vaos = new ArrayList<Integer>();
private List<Integer> vbos = new ArrayList<Integer>();
public RawModel loadToVAO(float[] positions) {
int vaoID = createVAO();
storeDataInAttributeList(0, positions);
unbindVAO();
return new RawModel(vaoID, positions.length / 3);
}
public void cleanUp() {
for (int vao : vaos) {
GL30.glDeleteVertexArrays(vao);
}
for (int vbo : vbos) {
GL15.glDeleteBuffers(vbo);
}
}
private int createVAO() {
int vaoID = GL30.glGenVertexArrays();
vaos.add(vaoID);
GL30.glBindVertexArray(vaoID);
return vaoID;
}
private void storeDataInAttributeList(int attributeNumber, float[] data) {
int vboID = GL15.glGenBuffers();
vbos.add(vboID);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID);
FloatBuffer buffer = storeDataInFloatBuffer(data);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
GL20.glVertexAttribPointer(attributeNumber, 3, GL11.GL_FLOAT, false, 0, 0);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
}
private void unbindVAO() {
GL30.glBindVertexArray(0);
}
private FloatBuffer storeDataInFloatBuffer(float[] data) {
FloatBuffer buffer = BufferUtils.createFloatBuffer(data.length);
buffer.put(data).position(0);
buffer.flip();
return buffer;
}
And my main Method:
public static void main(String[] args){
if(!glfwInit()){
throw new IllegalStateException("Failed");
}
System.out.println(GL11.glGetString(GL11.GL_VERSION));
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, 3);
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR, 4);
long window = GLFW.glfwCreateWindow(640, 480, "Hello World", 0, 0);
if(window == 0){
throw new IllegalStateException("Failed to create Window");
}
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(window, (vidmode.width() - 640) / 2, (vidmode.height() - 480) / 2);
glfwShowWindow(window);
Loader loader = new Loader();
Renderer renderer = new Renderer();
float[] vertices = {
-0.5f, 0.5f, 0f,
-0.5f, -0.5f, 0f,
0.5f, -0.5f, 0f,
0.5f, -0.5f, 0f,
0.5f, 0.5f, 0f,
-0.5f, 0.5f, 0f
};
RawModel model = loader.loadToVAO(vertices);
while(!glfwWindowShouldClose(window)){
renderer.prepare();
renderer.render(model);
glfwPollEvents();
}
loader.cleanUp();
GLFW.glfwTerminate();
}
So I have already tried:
Update drivers for Graphic-card, update java, update Windows, setting up a new eclipse, reinstall java and deleting .metadata in eclipse.
Can anyone pls help me?

According to the comment
I dont have implemented a shader yet
The state of the art way of rendering in OpenGL, would be to use a Shader.
If you don't use a shader, than you have to define the array of vertex data by glVertexPointer. glVertexPointer specifies a array for Fixed-Function vertex coordinate attribute. If you don't have a shader program, then you have to use the Fixed Function Pipeline.
private void storeDataInAttributeList(int attributeNumber, float[] data) {
int vboID = GL15.glGenBuffers();
vbos.add(vboID);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID);
FloatBuffer buffer = storeDataInFloatBuffer(data);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
GL11.glVertexPointer( 3, GL11.GL_FLOAT, 0, 0 ); // <---------
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
}
Further you have to enable the client-side capability for vertex coordinates by glEnableClientState( GL_VERTEX_ARRAY ):
public void render(RawModel model){
GL30.glBindVertexArray(model.getVaoID());
GL11.glEnableClientState( GL11.GL_VERTEX_ARRAY ); // <---------
GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, model.getVertexCount());
GL11.glDisableClientState( GL11.GL_VERTEX_ARRAY ); // <---------
GL30.glBindVertexArray(0);
}
Further note, that you have to creates the "GLCapabilities" instance and makes the OpenGL bindings available for use before you use an OpenGL instruction like GL30.glGenVertexArrays() and you have to ensure the the OpenGL context is current.
Call glfwMakeContextCurrent(window) and GL.createCapabilities() after creating the window and before any OpenGL instruction:
long window = GLFW.glfwCreateWindow(640, 480, "Hello World", 0, 0);
if(window == 0){
throw new IllegalStateException("Failed to create Window");
}
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(window, (vidmode.width() - 640) / 2, (vidmode.height() - 480) / 2);
glfwMakeContextCurrent(window); // <-----
glfwShowWindow(window);
GL.createCapabilities(); // <-----
.....
Finally you are missing glfwSwapBuffers int the render loop. glfwSwapBuffers Swaps the front and back buffers of the specified window. In other, simple words it binges the buffer where you rendered to, onto the screen:
while(!glfwWindowShouldClose(window)){
renderer.prepare();
renderer.render(model);
glfwSwapBuffers(window); // <-----
glfwPollEvents();
}
See also LWJGL 3 Guide - Getting Started

Related

Why does LWJGL (OpenGL) drawElements not draw?

I attempted to follow the LWJGL 3.2+ Tutorial on drawElements and get my LWJGL application to draw a quad. My code runs successfully but doesn't draw anything (apart from the basic window), no matter where I run my loopCycle method that should draw the quad. I assume it has to do with the change from Display (Tutorial) to GLFW (my code)? I saw some posts talking about Projection, View and Model matrices that I do not use (afaik), is that the issue why it doesn't display?
package org.tempest.game;
import org.lwjgl.*;
import org.lwjgl.glfw.*;
import org.lwjgl.opengl.*;
import org.lwjgl.system.*;
import java.nio.*;
import static org.lwjgl.glfw.Callbacks.*;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryStack.*;
import static org.lwjgl.system.MemoryUtil.*;
public class Graphics {
// The window handle
private long window;
// Window setup
private final String WINDOW_TITLE = "Test";
// 1920x1080, 1600x900 and 1200x675 are all 16:9 ratios
private final int WIDTH = 320;
private final int HEIGHT = 240;
// Quad variables
private int vaoId = 0;
private int vboId = 0;
private int vboiId = 0;
private int indicesCount = 0;
public static void main(String[] args) {
new Graphics().run();
}
public void run() {
System.out.println("Hello LWJGL " + Version.getVersion() + "!");
init();
setupQuad();
loop();
destroyOpenGL();
// Free the window callbacks and destroy the window
glfwFreeCallbacks(window);
glfwDestroyWindow(window);
// Terminate GLFW and free the error callback
glfwTerminate();
glfwSetErrorCallback(null).free();
}
private void init() {
// Setup an error callback. The default implementation
// will print the error message in System.err.
GLFWErrorCallback.createPrint(System.err).set();
// Initialize GLFW. Most GLFW functions will not work before doing this.
if ( !glfwInit() )
throw new IllegalStateException("Unable to initialize GLFW");
// Configure GLFW
glfwDefaultWindowHints(); // optional, the current window hints are already the default
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
// Create the window
window = glfwCreateWindow(WIDTH, HEIGHT, WINDOW_TITLE, NULL, NULL);
if ( window == NULL )
throw new RuntimeException("Failed to create the GLFW window");
// Setup a key callback. It will be called every time a key is pressed, repeated or released.
glfwSetKeyCallback(window, (window, key, scancode, action, mods) -> {
if ( key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE )
glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop
});
// Get the thread stack and push a new frame
try ( MemoryStack stack = stackPush() ) {
IntBuffer pWidth = stack.mallocInt(1); // int*
IntBuffer pHeight = stack.mallocInt(1); // int*
// Get the window size passed to glfwCreateWindow
glfwGetWindowSize(window, pWidth, pHeight);
// Get the resolution of the primary monitor
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
// Center the window
glfwSetWindowPos(
window,
(vidmode.width() - pWidth.get(0)) / 2,
(vidmode.height() - pHeight.get(0)) / 2
);
} // the stack frame is popped automatically
// Make the OpenGL context current
glfwMakeContextCurrent(window);
// Enable v-sync with 1
glfwSwapInterval(0);
// Make the window visible
glfwShowWindow(window);
}
private void loop() {
// Initialize variables for fps calculation
long time_start = System.nanoTime();
int frames = 0;
final double check_fps_time = 1d;
// Set the clear color
glClearColor(0.2f, 0.2f, 0.2f, 0.0f);
// TODO Where to initialize this?
//GL11.glViewport(0, 0, WIDTH, HEIGHT);
// Run the rendering loop until the user has attempted to close
// the window or has pressed the ESCAPE key.
while ( !glfwWindowShouldClose(window) ) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the framebuffer
glfwSwapBuffers(window); // swap the color buffers
// Count, calculate and display fps
frames++;
long time_now = System.nanoTime();
if ((double)(time_now - time_start)/1000000000 > check_fps_time) {
int fps_prediction = (int)(frames/check_fps_time);
System.out.println("FPS: " + fps_prediction);
frames = 0;
time_start = time_now;
}
// Poll for window events. The key callback above will only be
// invoked during this call.
glfwPollEvents();
loopCycle();
}
}
public void setupQuad() {
GL.createCapabilities();
// Vertices, the order is not important.
float[] vertices = {
-0.5f, 0.5f, 0f, // Left top ID: 0
-0.5f, -0.5f, 0f, // Left bottom ID: 1
0.5f, -0.5f, 0f, // Right bottom ID: 2
0.5f, 0.5f, 0f // Right left ID: 3
};
// Sending data to OpenGL requires the usage of (flipped) byte buffers
FloatBuffer verticesBuffer = BufferUtils.createFloatBuffer(vertices.length);
verticesBuffer.put(vertices);
verticesBuffer.flip();
// OpenGL expects to draw vertices in counter clockwise order by default
byte[] indices = {
// Left bottom triangle
0, 1, 2,
// Right top triangle
2, 3, 0
};
indicesCount = indices.length;
ByteBuffer indicesBuffer = BufferUtils.createByteBuffer(indicesCount);
indicesBuffer.put(indices);
indicesBuffer.flip();
// Create a new Vertex Array Object in memory and select it (bind)
// A VAO can have up to 16 attributes (VBOs) assigned to it by default
vaoId = GL30.glGenVertexArrays();
GL30.glBindVertexArray(vaoId);
// Create a new Vertex Buffer Object in memory and select it (bind)
// A VBO is a collection of Vectors which in this case resemble the location of each vertex.
vboId = GL15.glGenBuffers();
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesBuffer, GL15.GL_STATIC_DRAW);
// Put the VBO in the attributes list at index 0
GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0);
// Deselect (bind to 0) the VBO
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
// Deselect (bind to 0) the VAO
GL30.glBindVertexArray(0);
// Create a new VBO for the indices and select it (bind)
vboiId = GL15.glGenBuffers();
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW);
// Deselect (bind to 0) the VBO
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
}
public void loopCycle() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
// Bind to the VAO that has all the information about the vertices
GL30.glBindVertexArray(vaoId);
GL20.glEnableVertexAttribArray(0);
// Bind to the index VBO that has all the information about the order of the vertices
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
// Draw the vertices
GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_BYTE, 0);
// Put everything back to default (deselect)
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
GL20.glDisableVertexAttribArray(0);
GL30.glBindVertexArray(0);
}
public void destroyOpenGL() {
// Disable the VBO index from the VAO attributes list
GL20.glDisableVertexAttribArray(0);
// Delete the vertex VBO
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
GL15.glDeleteBuffers(vboId);
// Delete the index VBO
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
GL15.glDeleteBuffers(vboiId);
// Delete the VAO
GL30.glBindVertexArray(0);
GL30.glDeleteVertexArrays(vaoId);
}
public int getWIDTH() {
return WIDTH;
}
public int getHEIGHT() {
return HEIGHT;
}
}
I am a beginner and probably there are a number of things I need to look into to make this work. I would love to hear some guidance on what to look into to get my application to do something so I can take things from there. Thank you so much! :)
There is at least one issue with this code- it calls clear/draw/swap in the wrong order. Basically with OpenGL, the main loop should call clear() first, draw some things, and then call swapBuffers() to display the buffer contents.
The example instead: calls clear (ok, clear the buffer), swaps the buffers (here a blank window is shown, since the buffer is cleared), and then draws a bunch of stuff to the buffer. But the buffer contents is never displayed (since in the next cycle, the first operation is clear() again).
Below the slightly modified code; it draws a white rectangle - I am not totally sure about the usage of glBindBuffer (I used drawLine and drawTriangle in the past), but it's a start.
package sample;
import org.lwjgl.*;
import org.lwjgl.glfw.*;
import org.lwjgl.opengl.*;
import org.lwjgl.system.*;
import java.nio.*;
import static org.lwjgl.glfw.Callbacks.*;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryStack.*;
import static org.lwjgl.system.MemoryUtil.*;
public class DrawExample {
// The window handle
private long window;
// Window setup
private final String WINDOW_TITLE = "Test";
// 1920x1080, 1600x900 and 1200x675 are all 16:9 ratios
private final int WIDTH = 320;
private final int HEIGHT = 240;
// Quad variables
private int vaoId = 0;
private int vboId = 0;
private int vboiId = 0;
private int indicesCount = 0;
public static void main(String[] args) {
new DrawExample().run();
}
public void run() {
System.out.println("Hello LWJGL " + Version.getVersion() + "!");
init();
setupQuad();
loop();
destroyOpenGL();
// Free the window callbacks and destroy the window
glfwFreeCallbacks(window);
glfwDestroyWindow(window);
// Terminate GLFW and free the error callback
glfwTerminate();
glfwSetErrorCallback(null).free();
}
private void init() {
// Setup an error callback. The default implementation
// will print the error message in System.err.
GLFWErrorCallback.createPrint(System.err).set();
// Initialize GLFW. Most GLFW functions will not work before doing this.
if (!glfwInit())
throw new IllegalStateException("Unable to initialize GLFW");
// Configure GLFW
glfwDefaultWindowHints(); // optional, the current window hints are already the default
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
// Create the window
window = glfwCreateWindow(WIDTH, HEIGHT, WINDOW_TITLE, NULL, NULL);
if (window == NULL)
throw new RuntimeException("Failed to create the GLFW window");
// Setup a key callback. It will be called every time a key is pressed, repeated or released.
glfwSetKeyCallback(window, (window, key, scancode, action, mods) -> {
if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE)
glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop
});
// Get the resolution of the primary monitor
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
// Get the thread stack and push a new frame
try (MemoryStack stack = stackPush()) {
IntBuffer pWidth = stack.mallocInt(1); // int*
IntBuffer pHeight = stack.mallocInt(1); // int*
// Get the window size passed to glfwCreateWindow
glfwGetWindowSize(window, pWidth, pHeight);
// Center the window
glfwSetWindowPos(window, (vidmode.width() - pWidth.get(0)) / 2,
(vidmode.height() - pHeight.get(0)) / 2);
} // the stack frame is popped automatically
// Make the OpenGL context current
glfwMakeContextCurrent(window);
// Enable v-sync with 1
glfwSwapInterval(1);
// Make the window visible
glfwShowWindow(window);
}
private void loop() {
// Initialize variables for fps calculation
long time_start = System.nanoTime();
int frames = 0;
final double check_fps_time = 1d;
// Set the clear color
glClearColor(0.2f, 0.2f, 0.2f, 0.0f);
// TODO Where to initialize this?
// GL11.glViewport(0, 0, WIDTH, HEIGHT);
// Run the rendering loop until the user has attempted to close
// the window or has pressed the ESCAPE key.
while (!glfwWindowShouldClose(window)) {
// Count, calculate and display fps
frames++;
long time_now = System.nanoTime();
if ((double) (time_now - time_start) / 1000000000 > check_fps_time) {
int fps_prediction = (int) (frames / check_fps_time);
System.out.println("FPS: " + fps_prediction);
frames = 0;
time_start = time_now;
}
// Poll for window events. The key callback above will only be
// invoked during this call.
glfwPollEvents();
loopCycle();
glfwSwapBuffers(window); // swap the color buffers
}
}
public void setupQuad() {
GL.createCapabilities();
// Vertices, the order is not important.
float[] vertices = {-0.5f, 0.5f, 0f, // Left top ID: 0
-0.5f, -0.5f, 0f, // Left bottom ID: 1
0.5f, -0.5f, 0f, // Right bottom ID: 2
0.5f, 0.5f, 0f // Right left ID: 3
};
// Sending data to OpenGL requires the usage of (flipped) byte buffers
FloatBuffer verticesBuffer = BufferUtils.createFloatBuffer(vertices.length);
verticesBuffer.put(vertices);
verticesBuffer.flip();
// OpenGL expects to draw vertices in counter clockwise order by default
byte[] indices = {
// Left bottom triangle
0, 1, 2,
// Right top triangle
2, 3, 0};
indicesCount = indices.length;
ByteBuffer indicesBuffer = BufferUtils.createByteBuffer(indicesCount);
indicesBuffer.put(indices);
indicesBuffer.flip();
// Create a new Vertex Array Object in memory and select it (bind)
// A VAO can have up to 16 attributes (VBOs) assigned to it by default
vaoId = GL30.glGenVertexArrays();
GL30.glBindVertexArray(vaoId);
// Create a new Vertex Buffer Object in memory and select it (bind)
// A VBO is a collection of Vectors which in this case resemble the location of each vertex.
vboId = GL15.glGenBuffers();
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesBuffer, GL15.GL_STATIC_DRAW);
// Put the VBO in the attributes list at index 0
GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0);
// Deselect (bind to 0) the VBO
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
// Deselect (bind to 0) the VAO
GL30.glBindVertexArray(0);
// Create a new VBO for the indices and select it (bind)
vboiId = GL15.glGenBuffers();
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW);
// Deselect (bind to 0) the VBO
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
}
public void loopCycle() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Bind to the VAO that has all the information about the vertices
GL30.glBindVertexArray(vaoId);
GL20.glEnableVertexAttribArray(0);
// Bind to the index VBO that has all the information about the order of the vertices
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
// Draw the vertices
GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_BYTE, 0);
// Put everything back to default (deselect)
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
GL20.glDisableVertexAttribArray(0);
GL30.glBindVertexArray(0);
}
public void destroyOpenGL() {
// Disable the VBO index from the VAO attributes list
GL20.glDisableVertexAttribArray(0);
// Delete the vertex VBO
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
GL15.glDeleteBuffers(vboId);
// Delete the index VBO
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
GL15.glDeleteBuffers(vboiId);
// Delete the VAO
GL30.glBindVertexArray(0);
GL30.glDeleteVertexArrays(vaoId);
}
public int getWIDTH() {
return WIDTH;
}
public int getHEIGHT() {
return HEIGHT;
}
}

Depth not being render but instead is displaying overlay

I have an issue in my project where I am trying to draw a pyramid on screen but the depth is not being displayed.
public void create(float[] vertices, int[] indices, int numberOfVertices, int numberOfIndices) {
indexCount = numberOfIndices;
vao = gl.genVertexArrays();
gl.bindVertexArray(vao);
IntBuffer indicesBuffer = factory.create(indices);
ibo = gl.genBuffers();
gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL_STATIC_DRAW);
FloatBuffer verticesBuffer = factory.create(vertices);
vbo = gl.genBuffers();
gl.bindBuffer(GL_ARRAY_BUFFER, vbo);
gl.bufferData(GL_ARRAY_BUFFER, verticesBuffer, GL_STATIC_DRAW);
gl.vertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
gl.enableVertexAttribArray(0);
gl.bindBuffer(GL_ARRAY_BUFFER, 0);
gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
gl.bindVertexArray(0);
}
I create my mesh object with following code where Vertices and Indices are defined as :
private void createTriangles() {
float[] vertices = new float[] {
//x y z
-1.0f, -1.0f, 0.0f, //0
0.0f, 0.0f, 1.0f, //1
1.0f, -1.0f, 0.0f, //2
0.0f, 1.0f, 0.0f //3
};
int[] indices = new int[] {
0, 3, 1,
1, 3, 2,
2, 3, 0,
0, 1, 2
};
mesh.create(vertices, indices, 12, 12);
}
In order to display them to screen I call my render function from my game loop which is defined as.
public void render() {
gl.bindVertexArray(vao);
gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
gl.drawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, 0);
gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
gl.bindVertexArray(0);
}
To create my FloatBuffer and IntBuffer I have a factory class defined as.
public class BufferFactory {
public IntBuffer create(int[] indices) {
IntBuffer buffer = BufferUtils.createIntBuffer(indices.length);
buffer.put(indices);
buffer.flip();
return buffer;
}
public FloatBuffer create(float[] vertices) {
FloatBuffer buffer = BufferUtils.createFloatBuffer(vertices.length);
buffer.put(vertices);
buffer.flip();
return buffer;
}
}
So the issue i'm getting is that it should have drawn four triangles to screen to form a pyramid, however my output looks like this.
I have rotated the image to try and see the depth but it is a flat object.
I have tried to identify where the issue may be coming from by attempting to draw each triangle individually by changing my render method to gl.drawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, 0); So that it only draws one triangle. I have tried to draw all four faces individually and all are drawn to screen.
I found the issue. I was originally scaling the triangle such that
model.scale(new Vector3f(0.2f, 0.2f, 0.0f));
As a result the z axis was being multiplied by 0. Silly mistake, hope this helps someone in the future.

Basic openGL 3.2 Setup with lwjgl - Object not rendered

I am little bit desperate here.
I am trying to update/refactor an existing code written in legacy opengl to make use of the "modern way" of opengl version 3.2+.
It is written in Java with lwjgl. I already stripped away most of the functionality to test the basic setup. For me at the moment it is really just about setting up the vbo with vertices loaded from an obj file and render it. My problem is, that the display window stays empty. If it would display me just something, I would be really happy.
Maybe you guys can help me what I am missing here.
public class Mobile {
private final String texturePath = "../CGSS15Ex3MobileDS/dataEx3/Textures";
private int
width = 1200,
height = 800,
fps = 0,
cameraDist = 2000,
fillMode = GL_LINE,
ticksPerSecond = 60,
frameCounter = 0,
vaoId,
vboId,
vboiID,
pId,
vsId,
fsId;
private long
time,
lastTime,
lastFPS,
lastKeySpace,
frameCounterTime,
avgTime = 0;
private float
dx = 0f, // mouse x distance
dy = 0f, // mouse y distance
diffTime = 0f, // frame length
mouseSensitivity = 0.5f,
movementSpeed = 800.0f; // move 10 units per second.
private Fork fork;
private CameraController camera;
FloatBuffer kugelBuff, indexBuff;
int kugelVertCount;
static LinkedList<Integer> textureIDs = new LinkedList<>();
public Mobile() {
run();
}
private void run() {
init();
while (!exit()) {
update();
draw();
updateFPS();
}
fini();
}
private void init() {
// OpenGL Setup
// create display
try {
PixelFormat pixelFormat = new PixelFormat();
ContextAttribs contextAtrributes = new ContextAttribs(3, 2)
.withProfileCore(true)
.withForwardCompatible(true);
Display.setDisplayMode(new DisplayMode(width, height));
Display.setTitle("Mobile by Aaron Scheu");
Display.create(pixelFormat, contextAtrributes);
GL11.glClearColor(0.3f, 0.3f, 0.3f, 0f);
GL11.glViewport(0, 0, width, height);
} catch (LWJGLException e) {
e.printStackTrace();
System.exit(-1);
}
// setup scene //
setupSphere();
setupShaders();
setupTex();
// set Timer
frameCounterTime = lastFPS = getTime();
System.out.println("Start timer ...");
}
private void setupTex() {
for (String file : getTextureFiles(texturePath)) {
try {
TextureReader.Texture texture = TextureReader.readTexture(file);
textureIDs.add(glGenTextures());
GL13.glActiveTexture(GL13.GL_TEXTURE0);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureIDs.getLast());
// Upload tex and generate mipmap for scaling
glTexImage2D(
GL_TEXTURE_2D, 0, GL_RGB, texture.getWidth(), texture.getHeight(), 0,
GL_RGB, GL_UNSIGNED_BYTE, texture.getPixels()
);
GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
// Setup the ST coordinate system
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
// Setup what to do when the texture has to be scaled
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER,
GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER,
GL11.GL_LINEAR_MIPMAP_LINEAR);
} catch(IOException e) {
System.out.println(e);
}
}
}
private void setupShaders() {
// Load the vertex shader
// vsId = GLDrawHelper.compileShader("../CGSS15Ex3MobileDS/dataEx3/Shader/phong_vertex.glsl", GL20.GL_VERTEX_SHADER);
vsId = GLDrawHelper.compileShader("shader/vert_shader.glsl", GL20.GL_VERTEX_SHADER);
// Load the fragment shader
// fsId = GLDrawHelper.compileShader("../CGSS15Ex3MobileDS/dataEx3/Shader/phong_fragment.glsl", GL20.GL_FRAGMENT_SHADER);
fsId = GLDrawHelper.compileShader("shader/frac_shader.glsl", GL20.GL_FRAGMENT_SHADER);
// Create a new shader program that links both shaders
pId = GL20.glCreateProgram();
GL20.glAttachShader(pId, vsId);
GL20.glAttachShader(pId, fsId);
// Bind shader data to vbo attribute list
// GL20.glBindAttribLocation(pId, 0, "vert_in");
// GL20.glBindAttribLocation(pId, 1, "col_in");
// GL20.glBindAttribLocation(pId, 2, "tex0_in");
// GL20.glBindAttribLocation(pId, 3, "norm_in");
// Test Shader
GL20.glBindAttribLocation(pId, 0, "in_Position");
GL20.glBindAttribLocation(pId, 1, "in_Color");
GL20.glBindAttribLocation(pId, 2, "in_TextureCoord");
GL20.glLinkProgram(pId);
GL20.glValidateProgram(pId);
}
private void setupSphere() {
Model sphere = null;
try {
sphere = OBJLoader.loadModel(new File("sphere.obj"));
} catch (IOException e) {
e.printStackTrace();
Display.destroy();
System.exit(1);
}
kugelBuff = GLDrawHelper.directFloatBuffer(sphere.getVVVNNNTT());
indexBuff = GLDrawHelper.directFloatBuffer(sphere.getVertIndices());
kugelVertCount = sphere.getVertCount();
// Create a new Vertex Array Object in memory and select it (bind)
vaoId = GL30.glGenVertexArrays();
GL30.glBindVertexArray(vaoId);
// Create a new Vertex Buffer Object in memory and select it (bind)
vboId = GL15.glGenBuffers();
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, kugelBuff, GL15.GL_STATIC_DRAW);
// Attribute Pointer - list id, size, type, normalize, sprite, offset
GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 8*4, 0); // Vertex
// GL20.glVertexAttribPointer(1, 3, GL11.GL_FLOAT, false, 3, 0); // Color
GL20.glVertexAttribPointer(2, 2, GL11.GL_FLOAT, false, 8*4, 6*4); // UV Tex
// GL20.glVertexAttribPointer(3, 3, GL11.GL_FLOAT, false, 8*4, 3*4); // Normals
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
// Deselect (bind to 0) the VAO
GL30.glBindVertexArray(0);
// Create a new VBO for the indices and select it (bind) - INDICES
vboiID = GL15.glGenBuffers();
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiID);
GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indexBuff, GL15.GL_STATIC_DRAW);
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
}
private void update() {
// limit framerate
// Display.sync(ticksPerSecond);
// get time
time = getTime();
diffTime = (time - lastTime)/1000.0f;
lastTime = time;
// Distance mouse has been moved
dx = Mouse.getDX();
dy = Mouse.getDY();
// toggle wireframe
if(Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
if (time - lastKeySpace > 100) {
fillMode = fillMode == GL_FILL ? GL_LINE : GL_FILL;
glPolygonMode(GL_FRONT_AND_BACK, fillMode);
}
lastKeySpace = time;
}
// mouse control
camera.yaw(dx * mouseSensitivity);
camera.pitch(dy * mouseSensitivity);
// WASD control
if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
camera.walkForward(movementSpeed * diffTime);
}
if (Keyboard.isKeyDown(Keyboard.KEY_S)) {
camera.walkBackwards(movementSpeed * diffTime);
}
if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
camera.strafeLeft(movementSpeed * diffTime);
}
if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
camera.strafeRight(movementSpeed * diffTime);
}
}
private boolean exit() {
return Display.isCloseRequested() || Keyboard.isKeyDown(Keyboard.KEY_ESCAPE);
}
// runner is finished, clean up
private void fini() {
// glDisable(GL_DEPTH_BITS);
// Delete all textures
textureIDs.stream().forEach(GL11::glDeleteTextures);
// Delete the shaders
GL20.glUseProgram(0);
GL20.glDetachShader(pId, vsId);
GL20.glDetachShader(pId, fsId);
GL20.glDeleteShader(vsId);
GL20.glDeleteShader(fsId);
GL20.glDeleteProgram(pId);
// Select the VAO
GL30.glBindVertexArray(vaoId);
// Disable the VBO index from the VAO attributes list
GL20.glDisableVertexAttribArray(0);
GL20.glDisableVertexAttribArray(1);
// Delete the vertex VBO
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
GL15.glDeleteBuffers(vboId);
// Delete the index VBO
// GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
// GL15.glDeleteBuffers(vboiId);
// Delete the VAO
GL30.glBindVertexArray(0);
GL30.glDeleteVertexArrays(vaoId);
Display.destroy();
}
private void updateFPS() {
long time = getTime();
String title;
if (time - lastFPS > 1000) {
// Display.setTitle("FPS: " + fps);
title = "FPS: " + fps + " || avg time per frame: " + (avgTime != 0 ? avgTime/1000f : "-/-") + " ms";
Display.setTitle(title);
fps = 0;
lastFPS += 1000;
}
fps++;
// Frame Count over 1000
if (frameCounter == 1000) {
avgTime = time - frameCounterTime;
// System.out.println("Time for 1000 frames: " + avgTime + " ms.");
frameCounter = 0;
frameCounterTime = time;
}
frameCounter++;
}
private long getTime() {
return (Sys.getTime() * 1000 / Sys.getTimerResolution());
}
private void draw() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
GL20.glUseProgram(pId);
// Bind the texture
GL13.glActiveTexture(GL13.GL_TEXTURE0);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureIDs.get(0));
// Bind to the VAO that has all the information about the vertices
GL30.glBindVertexArray(vaoId);
GL20.glEnableVertexAttribArray(0);
// GL20.glEnableVertexAttribArray(1);
GL20.glEnableVertexAttribArray(2);
GL20.glEnableVertexAttribArray(3);
// Bind to the index VBO that has all the information about the order of the vertices
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiID);
// Draw the vertices
GL11.glDrawElements(GL11.GL_TRIANGLES, kugelVertCount, GL11.GL_UNSIGNED_BYTE, 0);
// Put everything back to default (deselect)
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
GL20.glDisableVertexAttribArray(0);
// GL20.glDisableVertexAttribArray(1);
GL20.glDisableVertexAttribArray(2);
GL20.glDisableVertexAttribArray(3);
GL30.glBindVertexArray(0);
GL20.glUseProgram(0);
Display.update();
}
private static String[] getTextureFiles(String directory) {
File pathfile = new File(directory);
File[] files = pathfile.listFiles( (File dir, String name) ->
name.endsWith(".jpg") || name.endsWith(".png")
);
return Arrays.stream(files).map(File::toString).toArray(String[]::new);
}
public static void main(String[] args) {
new Mobile();
}
}
Sorry for the code mess. Maybe this is better readable.
https://codeshare.io/1SEQK
Don't be desperate, amaridev.
When you can't get nothing rendered you have in general two option:
start from something basic and working (like this hello triangle from mine, it's jogl but you can port it to lwjgl very easily) and build on top of that
debug your application step by step
In case you decide for the second one, you may want to disable first and lighting, any matrix multiplication and any texturing:
check your rendering targets setup by testing if you see the clear color you set
check if glViewport and the fragment shader work by running an hardcoded vertex shader with:
gl_Position = vec4(4.0 * float(gl_VertexID % 2) - 1.0, 4.0 * float(gl_VertexID / 2) - 1.0, 0.0, 1.0);
like here, no matrices and a simple
glDrawArrays(GL_TRIANGLES, 3, 0);
you may want also to hardcode the color output
check if you are reading valid vertex attributes, by outputting each of them in turn to the color fragment shader
out Block
{
vec4 color
} outBlock;
...
outBlock.color = position;
in Block
{
vec4 color;
} inBlock;
outputColor = inBlock.color;
enable matrix multiplication and pass a simple hardcoded triangle to check if any matrix (first proj, then view and finally also model) works as expected
start fetching from your real sphere geometry
start fetching color
enable again texturing and start fetching texture coordinates again
output light and materials values to output color and then enable them back as well

Java rendering LWJGL 3.0.0

In this code i try to render a simple triangle on the screen, but it only shows the red background, i have tried every thing i know to debug but i just can't understand why it doesn't work
Hope somebody can help me, thanks in advance.
public float vertices[] = new float[]
{
-0.5f,-0.5f,0.0f,1.0f,
0.0f,1.0f,0.0f,1.0f,
0.0f,0.5f,0.0f,1.0f,
0.0f,1.0f,0.0f,1.0f,
0.5f,-0.5f,0.0f,1.0f,
0.0f,1.0f,0.0f,1.0f
};
public TEST()
{
}
public int start() throws IOException
{
glfwInit();
long window = glfwCreateWindow(1000, 1000, "HAHA", NULL, NULL);
glfwMakeContextCurrent(window);
glfwShowWindow(window);
GLFWKeyCallback keycallback = new GLFWKeyCallback()
{
#Override
public void invoke(long window, int key, int scancode, int action, int mods)
{
if(key==GLFW_KEY_ESCAPE&&action==GLFW_PRESS)
{
glfwSetWindowShouldClose(window, GLFW_TRUE);
}
}
};
glfwSetKeyCallback(window,keycallback );
GLFWErrorCallback errorcallback = new GLFWErrorCallback()
{
#Override
public void invoke(int error, long description)
{
System.out.println("ERROR CODE: " + error + " ERROR DESCRITPION: "+description);
}
};
glfwSetErrorCallback(errorcallback);
GL.createCapabilities();
glViewport(0, 0, 1000, 1000);
//////////////////////////
int VAO = glGenVertexArrays();
int VBO = glGenBuffers();
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
FloatBuffer buffer = FloatBuffer.allocate(vertices.length);
buffer.clear();
buffer.put(vertices);
buffer.flip();
glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
glVertexAttribPointer(0, 4, GL_FLOAT, false, 8, 0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 4, GL_FLOAT, false, 8, 4);
glEnableVertexAttribArray(1);
buffer.clear();
buffer=null;
System.gc();
glBindVertexArray(0);
///////////////////////
///////////////////////
LoadFile loader = new LoadFile("res/shader.vs", "res/shader.frag");
int vertexshader = glCreateShader(GL_VERTEX_SHADER);
int fragmentshader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(vertexshader, loader.readVertex());
glShaderSource(fragmentshader, loader.readFragment());
glCompileShader(vertexshader);
glCompileShader(fragmentshader);
System.out.println(glGetShaderInfoLog(vertexshader));
System.out.println(glGetShaderInfoLog(fragmentshader));
int program = glCreateProgram();
glAttachShader(program, vertexshader);
glAttachShader(program, fragmentshader);
glLinkProgram(program);
glDeleteShader(vertexshader);
glDeleteShader(fragmentshader);
System.out.println(glGetProgramInfoLog(program));
///////////////////////////
boolean running=true;
while(running&&glfwWindowShouldClose(window)==GLFW_FALSE)
{
glfwPollEvents();
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
glUseProgram(program);
glBindVertexArray(VAO);
glDrawArrays(GL_TRIANGLES, 0, 3);
glBindVertexArray(0);
glUseProgram(0);
glfwSwapInterval(1);
glfwSwapBuffers(window);
}
System.out.println(glGetError());
glfwTerminate();
return 0;
}
My vertex shader
#version 330 core
layout (location = 0) in vec4 position;
layout (location = 1) in vec4 colorin;
out vec4 colorout;
void main()
{
gl_Position = position;
colorout=colorin;
}
My fragment shader
#version 330 core
out vec4 color;
in vec4 colorout;
void main()
{
color = colorout;
}
EDIT: I just saw that this was 1 day old question.. but oh well..
I have my suspicion here:
FloatBuffer buffer = FloatBuffer.allocate(vertices.length);
buffer.clear();
buffer.put(vertices);
buffer.flip();
glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
Have you tried replacing this with BufferUtils from lwjgl library itself? It would turn out to be something like this:
FloatBuffer buff = BufferUtils.createFloatBuffer(vertices.length);
buff.put(vertices);
buff.flip();
Or, if you want the manual one..
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(vertices.length * Float.BYTES);
byteBuffer.order(ByteOrder.nativeOrder());
FloatBuffer floatBuffer = byteBuffer.asFloatBuffer();
floatBuffer.put(vertices);
floatBuffer.flip();
Stride and offsets are specified in bytes, so the stride for 8 floats representing 2 vec4s should be 32, and the offset for the color should be 16.
glVertexAttribPointer(0, 4, GL_FLOAT, false, 32, 0);
glVertexAttribPointer(1, 4, GL_FLOAT, false, 32, 16);

Textures are black in JOGL using VAO

So far, I used the deprecated immediate mode rendering, and I'm trying to switch to VAO then VBO. 2D quads are normally rendered using VAO, but when I'm trying to attach a texture, it remains black. I would really appreciate if somebody could take a look at my code, and point out the part where I'm wrong.
public class CSpriteVAO {
/*VAO*/
private FloatBuffer vertices;
private ShortBuffer indices;
private FloatBuffer textures;
private int VAOVertices;
private int VAOIndices;
private int VAOTextures;
/*SPRITE*/
private String mTexture;
private CPoint mPosition;
private CPoint mDimension;
private CPreferences mPreferences;
public CSpriteVAO(GL2 gl, CPreferences preferences, String spriteID, CRectangle dimensions){
mPreferences = preferences;
mTexture = spriteID;
mDimension = new CPoint(dimensions.width, dimensions.height);
mPosition = new CPoint(dimensions.x, dimensions.y);
CCreateVAO(gl);
}
public void onDraw(GL2 gl){
gl.glLoadIdentity();
CBindTexture(gl);
CDraw(gl);
}
private void CDraw(GL2 gl){
//gl.glCullFace(GL2.GL_CW);
gl.glTranslatef(mPosition.x, mPosition.y, 0);
gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, VAOVertices);
gl.glVertexPointer(3, GL2.GL_FLOAT, 0, 0);
gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, VAOTextures);
gl.glTexCoordPointer(2, GL2.GL_FLOAT, 0, VAOTextures);
gl.glBindBuffer(GL2.GL_ELEMENT_ARRAY_BUFFER, VAOIndices);
gl.glDrawElements(GL2.GL_TRIANGLES, indices.capacity(), GL2.GL_UNSIGNED_SHORT, 0);
gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);
}
private void CCreateVAO(GL2 gl){
//float[] textureArray = {0f, 1f, 1f, 1f, 1f, 0f, 0f, 0f};
float[] textureArray = {0f, 0f, 1f, 0f, 1f, 1f, 0f, 1f};
textures = Buffers.newDirectFloatBuffer(textureArray.length);
textures.put(textureArray);
textures.flip();
float[] vertexArray = {0, mDimension.y, 0,
mDimension.x, mDimension.y, 0,
mDimension.x, 0, 0,
0, 0, 0};
vertices = Buffers.newDirectFloatBuffer(vertexArray.length);
vertices.put(vertexArray);
vertices.flip();
short[] indexArray = {0, 1, 2, 0, 2, 3};
indices = Buffers.newDirectShortBuffer(indexArray.length);
indices.put(indexArray);
indices.flip();
int[] temp = new int[3];
gl.glGenBuffers(3, temp, 0);
VAOTextures = temp[0];
gl.glBindBuffer(GL2.GL_ELEMENT_ARRAY_BUFFER, VAOTextures);
gl.glBufferData(GL2.GL_ELEMENT_ARRAY_BUFFER, textures.capacity() * Buffers.SIZEOF_FLOAT, textures, GL2.GL_STATIC_DRAW);
gl.glBindBuffer(GL2.GL_ELEMENT_ARRAY_BUFFER, 0);
VAOVertices = temp[1];
gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, VAOVertices);
gl.glBufferData(GL2.GL_ARRAY_BUFFER, vertices.capacity() * Buffers.SIZEOF_FLOAT, vertices, GL2.GL_STATIC_DRAW);
gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, 0);
VAOIndices = temp[2];
gl.glBindBuffer(GL2.GL_ELEMENT_ARRAY_BUFFER, VAOIndices);
gl.glBufferData(GL2.GL_ELEMENT_ARRAY_BUFFER, indices.capacity() * Buffers.SIZEOF_SHORT, indices, GL2.GL_STATIC_DRAW);
gl.glBindBuffer(GL2.GL_ELEMENT_ARRAY_BUFFER, 0);
}
protected void CBindTexture(GL2 gl){
if (mTexture != CUtils.CurrentTexture){
if (mTexture != null){
CAssets.CWGGetTexture(mTexture).enable(gl);
CAssets.CWGGetTexture(mTexture).bind(gl);
}
CUtils.CurrentTexture = mTexture;
}
}
}
For the record: my vcard reports to have OpenGl 4.3.0 with (obviously) VAO support. Immediate rendering with textures is working fine.
I would really appreciate any kind of help. Many thanks in advance.
Check your texture coordinates.
If that does not work, check that you have set vertex color to white (so it will display colors as they show in the texture).

Categories