1
$\begingroup$

I’ve been trying to render a texture on the whole screen in OpenGL 4.1 using the Core profile and followed a few tutorials on the matter, but all I have so far is a blank screen.

I tried using my texture coordinates as color components and got the result I expected so the vertice data must be in order, but using the dimensions of the texture as color components I determined the size of the texture in my shader is 1x1 when it should be 2x2, so I guess I am doing something wrong when uploading it to the GPU.

This is my pixel data:

const GLubyte pixels[] = {
    255, 255, 255, 255,     0, 0, 0, 255,
    0, 0, 0, 255,           255, 255, 255, 255,
};

This is how I load my texture:

glGenTextures(1, &texture);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)pixels);

I also tried using a buffer:

glGenTextures(1, &texture);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);
glGenBuffers(1, &texture_buffer);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, texture_buffer);
glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(pixels), pixels, GL_STATIC_DRAW);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)0);

And this is how I render:

glUseProgram(shader_program);
// Binding my vba and vbo, uploading vertices.
glUniform1i(texture_location, 0);
// Enabling vertex attrib arrays.
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);
// Drawing arrays, disabling vertex attrib arrays.

I have also put the whole source file on pastebin, it uses GLFW for windowing and does some basic error checking.

I’d be really grateful if someone could point out what I am missing here.

$\endgroup$
0

1 Answer 1

2
$\begingroup$

You seem to not change GL_TEXTURE_MIN_FILTER and not fill all the mipmap layers. This will usually result in the texture not being applied, since by default the filter uses mipmapping.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.