• Create Account

### #ActualSeraphLance

Posted 15 October 2012 - 06:21 PM

For some reason, I can't get the texture to show on a fullscreen quad I'm drawing. I've co-opted some of the learning resource sites' code, but into (poorly written) C++ so my OGL calls might be a bit mangled and scattered, so... uhh... please forgive the probably hideous separation of logic. Most of the relevant code is below:

Rendering (bottom-level) code, the three functions are called in order of appearance in a higher function:
[source lang="cpp"]void RenderConfiguration::setRenderState(){ glEnable(getTextureType()); glUseProgram(scene_->getProgram()); glActiveTexture(GL_TEXTURE0); glBindTexture(getTextureType(), texture_); glUniform1i(scene_->getUniforms()[0], 0); glBindBuffer(GL_ARRAY_BUFFER,scene_->getVertexBuffer()); glVertexAttribPointer(scene_->getAttributes()[0],2,GL_FLOAT, GL_FALSE, sizeof(GLfloat)*2, (void*)0); glEnableVertexAttribArray(scene_->getAttributes()[0]); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, scene_->getElementBuffer());}void RenderConfiguration::draw(){ glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, (void*)0);}void RenderConfiguration::resetRenderState(){ glDisableVertexAttribArray(scene_->getAttributes()[0]); glDisable(getTextureType());}[/source]
#version 110
attribute vec2 position;
varying vec2 texcoord;
void main()
{

gl_Position = vec4(position, 0.0, 1.0);
texcoord = position * vec2(0.5) + vec2(0.5);
}


#version 110
uniform sampler2D texture;
in vec2 texcoord;

void main()
{
gl_FragColor = texture2D(texture, texcoord);
//gl_FragColor = vec4(texcoord.x, texcoord.y, 0.0, 1.0);
//gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);
}

There's a bit more initialization logic I can piece together on request, but this is all of the actual drawing stuff.

I've been fiddling around with debugging options for the better part of the day, and this is what I've figured out or verified so far:
• The shaders and the program have all compiled successfully. I've got some code inserted during the compilations that ensure it, and I've checked them with gDEBugger.
• textureType() resolves to GL_TEXTURE_2D in this particular example, and all of the getters resolve to (valid) resource handles.
• the texture, shaders, and program all have a valid handle.
• the texture is in memory and looks like it should (and certainly doesnt look like a black screen). I've checked this in gDEBugger.
• the attribute and uniform both have valid handles.
• the vertices are properly packed into a VBO. I checked this with gDEBugger, and I've done test renders with other channels than the texture.
• The quad itself is in a drawable state, i.e. I can render images straight from the fragment shader, like the two alternate gl_fragColor assignments commented out.
Pretty much the only thing left that I can guess might be causing the problem is the sampler, but I don't really know how to test its value. Failing that, does anything stand out like a sore thumb?

Edit: Seems the problem was that I forgot to call glTexParameter to set the filtering to linear instead of whatever mip filtering the default is. Not sure I've ever spent so long debugging a program before...

### #2SeraphLance

Posted 15 October 2012 - 01:10 AM

For some reason, I can't get the texture to show on a fullscreen quad I'm drawing. I've co-opted some of the learning resource sites' code, but into (poorly written) C++ so my OGL calls might be a bit mangled and scattered, so... uhh... please forgive the probably hideous separation of logic. Most of the relevant code is below:

Rendering (bottom-level) code, the three functions are called in order of appearance in a higher function:
[source lang="cpp"]void RenderConfiguration::setRenderState(){ glEnable(getTextureType()); glUseProgram(scene_->getProgram()); glActiveTexture(GL_TEXTURE0); glBindTexture(getTextureType(), texture_); glUniform1i(scene_->getUniforms()[0], 0); glBindBuffer(GL_ARRAY_BUFFER,scene_->getVertexBuffer()); glVertexAttribPointer(scene_->getAttributes()[0],2,GL_FLOAT, GL_FALSE, sizeof(GLfloat)*2, (void*)0); glEnableVertexAttribArray(scene_->getAttributes()[0]); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, scene_->getElementBuffer());}void RenderConfiguration::draw(){ glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, (void*)0);}void RenderConfiguration::resetRenderState(){ glDisableVertexAttribArray(scene_->getAttributes()[0]); glDisable(getTextureType());}[/source]
#version 110
attribute vec2 position;
varying vec2 texcoord;
void main()
{

gl_Position = vec4(position, 0.0, 1.0);
texcoord = position * vec2(0.5) + vec2(0.5);
}


#version 110
uniform sampler2D texture;
in vec2 texcoord;

void main()
{
gl_FragColor = texture2D(texture, texcoord);
//gl_FragColor = vec4(texcoord.x, texcoord.y, 0.0, 1.0);
//gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);
}

There's a bit more initialization logic I can piece together on request, but this is all of the actual drawing stuff.

I've been fiddling around with debugging options for the better part of the day, and this is what I've figured out or verified so far:
• The shaders and the program have all compiled successfully. I've got some code inserted during the compilations that ensure it, and I've checked them with gDEBugger.
• textureType() resolves to GL_TEXTURE_2D in this particular example, and all of the getters resolve to (valid) resource handles.
• the texture, shaders, and program all have a valid handle.
• the texture is in memory and looks like it should (and certainly doesnt look like a black screen). I've checked this in gDEBugger.
• the attribute and uniform both have valid handles.
• the vertices are properly packed into a VBO. I checked this with gDEBugger, and I've done test renders with other channels than the texture.
• The quad itself is in a drawable state, i.e. I can render images straight from the fragment shader, like the two alternate gl_fragColor assignments commented out.
Pretty much the only thing left that I can guess might be causing the problem is the sampler, but I don't really know how to test its value. Failing that, does anything stand out like a sore thumb?

### #1SeraphLance

Posted 15 October 2012 - 01:05 AM

For some reason, I can't get the texture to show on a fullscreen quad I'm drawing. I've co-opted some of the learning resource sites' code, but into (poorly written) C++ so my OGL calls might be a bit mangled and scattered, so... uhh... please forgive the probably hideous separation of logic. Most of the relevant code is below:

Rendering (bottom-level) code, the three functions are called in order of appearance in a higher function:
[source lang="cpp"]void RenderConfiguration::setRenderState(){ glEnable(getTextureType()); glUseProgram(scene_->getProgram()); glActiveTexture(GL_TEXTURE0); glBindTexture(getTextureType(), texture_); glUniform1i(scene_->getUniforms()[0], 0); glBindBuffer(GL_ARRAY_BUFFER,scene_->getVertexBuffer()); glVertexAttribPointer(scene_->getAttributes()[0],2,GL_FLOAT, GL_FALSE, sizeof(GLfloat)*2, (void*)0); glEnableVertexAttribArray(scene_->getAttributes()[0]); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, scene_->getElementBuffer());}void RenderConfiguration::draw(){ glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, (void*)0);}void RenderConfiguration::resetRenderState(){ glDisableVertexAttribArray(scene_->getAttributes()[0]); glDisable(getTextureType());}[/source]
#version 110
attribute vec2 position;
varying vec2 texcoord;
void main()
{

gl_Position = vec4(position, 0.0, 1.0);
texcoord = position * vec2(0.5) + vec2(0.5);
}


#version 110
uniform sampler2D texture;
in vec2 texcoord;

void main()
{
gl_FragColor = texture2D(texture, texcoord);
//gl_FragColor = vec4(texcoord.x, texcoord.y, 0.0, 1.0);
//gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);
}

There's a bit more initialization logic I can piece together on request, but this is all of the actual drawing stuff.

I've been fiddling around with debugging options for the better part of the day, and this is what I've figured out so far:
• The shaders and the program have all compiled successfully. I've got some code inserted during the compilations that ensure it, and I've checked them with gDEBugger.
• the texture, shaders, and program all have a valid handle.
• the texture is in memory and looks like it should (and certainly doesnt look like a black screen). I've checked this in gDEBugger.
• the attribute and uniform both have valid handles.
• the vertices are properly packed into a VBO. I checked this with gDEBugger, and I've done test renders with other channels than the texture.
• The quad itself is in a drawable state, i.e. I can render images straight from the fragment shader, like the two alternate gl_fragColor assignments commented out.
Pretty much the only thing left that I can guess might be causing the problem is the sampler, but I don't really know how to test its value. Failing that, does anything stand out like a sore thumb?

PARTNERS