0

Program compiles fine. Quads print. Trying to insert a 32 bit png, but it only prints a white box. What am I doing wrong? I've spent a few days trying to figure it out doing countless tutorials. I don't want to give up.

GLfloat cancelButtonVert[]
{
    0.1367f, -0.928f, 0.0f, 0.0f, 0.0f,
    0.4833f, -0.928f, 0.0f, 1.0f, 0.0f,
    0.4833f, -0.744f, 0.0f, 1.0f, 1.0f,
    0.1367f, -0.744f, 0.0f,    0.0f, 1.0f     
};

const unsigned int buttonIndices[]
{
    0, 1, 2,
    2, 3, 0,

};
......

It's all set up with in classes and functions, but I will try to show the whole draw.

.....
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(m_vertices[0]) * 5, 0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(m_vertices[0]) * 5, (void*)(sizeof(m_vertices[0]) * 3));
glEnableVertexAttribArray(1);

.....

void Texture::loadTexture()
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
unsigned char *texData = stbi_load(m_fileLocation.c_str(), &m_width, &m_height, &m_bitDepth, 0);
if (!texData)
{
    printf("Failed to find: %s\n", m_fileLocation.c_str());
    return;
}
glGenTextures(1, &m_textureId);
glBindTexture(GL_TEXTURE_2D, m_textureId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
glGenerateMipmap(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0);
stbi_image_free(texData);
}

void Texture::useTexture()
{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_textureId);
}
shaderList[0].useShader();
    uniformModel = shaderList[0].getModelLocation();
    uniformTexture = shaderList[0].getUniformTexture();
    //Draw Boxes
    model = glm::mat4();
    model = glm::translate(model, glm::vec3(0.0f, 0.0f, 0.0f));
    model = glm::scale(model, glm::vec3(1.0f, 1.0f, 1.0f));
    glUniformMatrix4fv(uniformModel, 3, GL_FALSE, glm::value_ptr(model));
    cancelButton.useTexture();
    glUniform1i(uniformTexture, 0);
    meshlist[0]->renderMesh();

The fragment shader.

#version 330

in vec4 vCol;
in vec2 TexCoord;

out vec4 color;

uniform sampler2D theTexture;

void main()
{
    color = texture(theTexture, TexCoord);
}

The Vertex Shader.

#version 330

layout (location = 0) in vec3 pos;
layout (location = 1) in vec2 tex;

out vec4 vCol;
out vec2 TexCoord;

uniform mat4 model;
uniform mat4 projection;

void main()
{
    gl_Position = projection * model * vec4(pos, 1.0);
    vCol = vec4(clamp(pos, 0.0f, 1.0f), 1.0f);

    TexCoord = tex;
}
  • Does `glGetError()` return any errors during your drawing? Also, if you change the fragment shader to simply return the texture coordinates in the red and green channel, what do you see? – user1118321 Jun 07 '18 at 05:35
  • Ty, so much. I am very new to programming. I've only been doing it for less than 3 months. Still haven't fixed it, but you have brought me into the right direction. I didn't even know about glGetError(). I'm a better debugger now. I was still getting white boxes with returning color as texture coords, and console is printing Error 1281 at the end of my while loop. I will look into that now. – Serial_Seth Jun 07 '18 at 17:36
  • @Rabbid76 vertex shader added. – Serial_Seth Jun 07 '18 at 18:37
  • I don't mean to whine, but I've been at it for 6 hours. I still can't get the results I want. I made all of the changes @Rabbid76 suggested. Right now I am programming everything inline to help me put a place on the glGetError(); scenario. Hat tip user^^^ . Right now in my OOP program I am getting a 1281 error and a 1282 error. I don't know exactly where. I probed the the shader class with a little error lifting, but that 1281 error keeps popping in my vectorIndex.useShader function, but I still can't yet isolate the 1282 error. The thing is if I system pause the 82 keeps repeating. – Serial_Seth Jun 08 '18 at 05:54
  • and no, frag out by index is still printing white. – Serial_Seth Jun 08 '18 at 05:55

1 Answers1

0

Projection was out of wack. The reason I was getting all of those 1281 and 12 82 GLerrors was the fact that I was calling the wrong vector index, so I could see a draw. I saw a draw and assumed I was heading in the right direction.

If I called what I knew was right, all the drawing happened off screen.

What I did was delete the projection matrix in my shader since all I wanted was a 2d rendering of a gui window with calculated pixel ratios in a calculated position.

I will keep model in the shader if I want to tweak things in the future.

All of your help made me a better programmer. @Rabbid76 all of your suggestions were things I needed to do. Ty all.

Corrected Shader

#version 330

layout (location = 0) in vec3 pos;
layout (location = 1) in vec2 tex;

out vec4 vCol;
out vec2 TexCoord;

uniform mat4 model;


void main()
{
gl_Position = model * vec4(pos, 1.0);
vCol = vec4(clamp(pos, 0.0f, 1.0f), 1.0f);

TexCoord = tex;

}