简体   繁体   中英

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. 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. 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

    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

nm, i've solved it.

Somehow copying the example shaders from the lwjgl for the texture quads is interfering with my non textured quad.

So for all those following the lwjgl tutorials on the wiki. the Texture quad shaders are not compatible with the colored quad shaders.

Still need to wait a couple of days before i can check this awnser

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