繁体   English   中英

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

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

我出于学习目的制作了opengl引擎,并在后来的体育场中使用它开发了一些游戏/应用。 现在,随着引擎的最新迭代,我似乎无法找出为什么我的四边形没有着色。

每个顶点由4个坐标(x,y,z,w)和4个色坐标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

nm,我已经解决了。

以某种方式从lwjgl复制示例着色器以获取纹理四边形会干扰我的非纹理四边形。

因此,对于所有遵循Wiki上的lwjgl教程的用户。 Texture Quad着色器与彩色Quad着色器不兼容。

仍然需要等待几天,然后我才能检查该篷

暂无
暂无

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

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