简体   繁体   English

需要一双新的眼睛来找出为什么我的四边形没有被着色

[英]need a new pair of eyes to find out why my quads aren't being colored

i am making a opengl engine for learning purposes and in a later stadium develop some games/apps with it. 我出于学习目的制作了opengl引擎,并在后来的体育场中使用它开发了一些游戏/应用。 Now with the newest iteration of my engine i cant seem to find out why my quads aren't being colored. 现在,随着引擎的最新迭代,我似乎无法找出为什么我的四边形没有着色。

Each vertex is composed of 4 coords (x, y, z, w)and 4 colorcoords r, g, b, a. 每个顶点由4个坐标(x,y,z,w)和4个色坐标r,g,b,a组成。 As far as i can tell the values i pass into the vertices are correct 据我所知,我传递给顶点的值是正确的

The offset calculations are hidden away in a seperate static class. 偏移量计算隐藏在单独的静态类中。 i have added it at the bottom of the post. 我已经在帖子底部添加了它。

    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);

My render call is in another class that i call after i passed through the vaoId, vboIID, the amount of indices and the 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);

Seperate static class with offset calculations 单独的静态类与偏移量计算

// 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;

As far as i can tell my offset calculations are correct. 据我所知,我的偏移量计算是正确的。 I had positions reserved for texture mapping but i removed them to see if those aren't causing any problems. 我保留了用于纹理贴图的位置,但是我删除了它们以查看它们是否不会引起任何问题。

A full version of the code is at github https://github.com/darR3Ke/EngineWorks-2.0 完整版本的代码位于github https://github.com/darR3Ke/EngineWorks-2.0

nm, i've solved it. nm,我已经解决了。

Somehow copying the example shaders from the lwjgl for the texture quads is interfering with my non textured quad. 以某种方式从lwjgl复制示例着色器以获取纹理四边形会干扰我的非纹理四边形。

So for all those following the lwjgl tutorials on the wiki. 因此,对于所有遵循Wiki上的lwjgl教程的用户。 the Texture quad shaders are not compatible with the colored quad shaders. Texture Quad着色器与彩色Quad着色器不兼容。

Still need to wait a couple of days before i can check this awnser 仍然需要等待几天,然后我才能检查该篷

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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