我正在制作一个用于学习目的的opengl引擎,并在以后的体育场内开发一些游戏/应用程序。现在我的引擎的最新迭代似乎无法找出为什么我的四边形没有着色。
每个顶点由4个coords(x,y,z,w)和4个colorcoords r,g,b,a组成。据我所知,我传入顶点的值是正确的
偏移计算隐藏在单独的静态类中。我把它添加到帖子的底部。
Vertex[] vertices = new Vertex[] { v0, v1, v2, v3 };
verticesBuffer = BufferUtils.createFloatBuffer(vertices.length * ELEMENT);
for (int i = 0; i < vertices.length; i++) {
verticesBuffer.put(vertices[i].getElements());
}
verticesBuffer.flip();
indicesBuffer = BufferUtils.createByteBuffer(indices.length);
indicesBuffer.put(indices);
indicesBuffer.flip();
int vaoId = glGenVertexArrays();
glBindVertexArray(vaoId);
int vboId = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vboId);
glBufferData(GL_ARRAY_BUFFER, verticesBuffer, GL_STATIC_DRAW);
glVertexAttribPointer(0, POSITION_ELEMENT, GL_FLOAT, false, ELEMENT_BYTES, POSITION_OFFSET);
glVertexAttribPointer(1, COLOR_ELEMENTS, GL_FLOAT, false, ELEMENT_BYTES, COLOR_OFFSET);
glBindBuffer(GL_ARRAY_BUFFER, 0);
int vboIId = glGenBuffers();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIId);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
Shaders shader = new Shaders();
int vsId = shader.load("shaders/shader.vert", GL_VERTEX_SHADER);
int fsId = shader.load("shaders/shader.frag", GL_FRAGMENT_SHADER);
pId = glCreateProgram();
glAttachShader(pId, vsId);
glAttachShader(pId, fsId);
glBindAttribLocation(pId, 0, "in_Position");
glBindAttribLocation(pId, 1, "in_Color");
glBindAttribLocation(pId, 2, "in_TextureCoord");
glLinkProgram(pId);
glValidateProgram(pId);
我的渲染调用是在我通过vaoId,vboIID,索引量和pId后调用的另一个类中
glClear(GL_COLOR_BUFFER_BIT); // scherm schoonmaken
glUseProgram(pId);
glBindVertexArray(vaoId);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIId);
glDrawElements(GL_TRIANGLES, amount_of_indices, GL_UNSIGNED_BYTE, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glBindVertexArray(0);
使用偏移计算分隔静态类
// Amount of bytes per element
static final int BYTES_PER_ELEMENT = 4;
// Elements per parameter
static final int POSITION_ELEMENT = 4;
static final int COLOR_ELEMENTS = 4;
static final int TEXTURE_ELEMENTS = 2;
// Bytes per parameter
static final int POSITION_BYTES = POSITION_ELEMENT * BYTES_PER_ELEMENT;
static final int COLOR_BYTES = COLOR_ELEMENTS * BYTES_PER_ELEMENT;
static final int TEXTURE_BYTES = TEXTURE_ELEMENTS * BYTES_PER_ELEMENT;
// Byte offset per parameter
static final int POSITION_OFFSET = 0;
static final int COLOR_OFFSET = POSITION_OFFSET + POSITION_BYTES;
static final int TEXTURE_OFFSET = COLOR_OFFSET + COLOR_BYTES;
// Amount of elements per vertex
static final int ELEMENT = POSITION_ELEMENT + COLOR_ELEMENTS + TEXTURE_ELEMENTS;
// Byte size per vertex
static final int ELEMENT_BYTES = POSITION_BYTES + COLOR_BYTES + TEXTURE_BYTES;
据我所知,我的偏移计算是正确的。我为纹理映射保留了位置,但我删除它们以查看它们是否没有引起任何问题。
完整版代码位于github https://github.com/darR3Ke/EngineWorks-2.0
答案 0 :(得分:1)
nm,我已经解决了。
以某种方式从lwjgl复制纹理四边形的示例着色器会干扰我的非纹理四边形。
所以那些关注维基的lwjgl教程的人。纹理四边形着色器与彩色四边形着色器不兼容。
还需要等待几天才能检查这个awnser