简体   繁体   中英

LWJGL glVertexAttribPointer index switching

As I'm learning OpenGL through LWJGL, I've been running through the tutorials on the LWJGL wiki. Specifically, this one .

My problem is, that despite the fact that I have duplicated that code, call for call, function for function, the two vertex attribute pointers need to be switched (so the code looks like this:

GL20.glVertexAttribPointer(1, 4, GL11.GL_FLOAT, false, Vertex.sizeInBytes, 
    // Put the colors in attribute list 1
GL20.glVertexAttribPointer(0, 4, GL11.GL_FLOAT, false, Vertex.sizeInBytes,
    Vertex.elementBytes * 4);

Switching it so that the position index is 1 and the color index is 0, makes a nice gradient render, as expected. However, if I run it with the indices switched (the way I think it should work, I get this:

令人困惑的精神错乱

Clearly, after studying this render for a while, the position and color data have been switched, and thus, switching the index numbers completely solves the problem, but I'm pretty sure I've followed everything correctly. What is wrong with the code? Why is this being such a bastard?

You should not be hardcoding attribute id's like that, and just hoping that they end up linked to the right shader attributes.

You need to either use glBindAttribLocation (before glLinkProgram), or glGetAttribLocation, so that you can map shader variables to their id number.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM