How to get texelFetchOffset to wrap around? - opengl

I create my textures like this:
this->width = width;
this->height = height;
glGenFramebuffers(1, &framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
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);
switch (components) {
case 1: glTexImage2D(GL_TEXTURE_2D, 0, GL_R16F, width, height, 0, GL_RED, GL_HALF_FLOAT, 0); break;
case 2: glTexImage2D(GL_TEXTURE_2D, 0, GL_RG16F, width, height, 0, GL_RG, GL_HALF_FLOAT, 0); break;
case 3: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, width, height, 0, GL_RGB, GL_HALF_FLOAT, 0); break;
case 4: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_HALF_FLOAT, 0); break;
default: Log::Write("Unknown format");
}
if(GL_NO_ERROR != glGetError()) Log::Write("Could not create texture");
GLuint colorbuffer;
glGenRenderbuffers(1, &colorbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, colorbuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
if(GL_NO_ERROR != glGetError()) Log::Write("Could not attach framebuffer");
if(GL_FRAMEBUFFER_COMPLETE != glCheckFramebufferStatus(GL_FRAMEBUFFER)) Log::Write("Could not create framebuffer");
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
But in my shader texelFetchOffset does not seem to wrap around the edges of the texture. What am I doing wrong?

Texture coord wrapping is sampler state, the texelFetch family of functions completely bypass the sampling and access the data store of the texture directly. It will never do the coordinate wrapping for you.

Related

OpenGL: Framebuffer, incomplete texture attachment

I've searched for couple hours for a solution to my problem.
First of all. I have HD 7800 series amd GPU, newest drivers.
I'm trying to create framebuffer class which has all the framebuffer functions I will need. It seems I got renderbuffers to work, but drawing to texture is causing really weird errors.
FrameBuffer::FrameBuffer(int width, int height)
{
createFrameBuffer();
// createDepthBufferAttachment(width, height); //commented out for testing (THIS WORKS)
createTextureAttachment(width, height);
// createDepthTextureAttachment(width, height); //commented out for testing
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE){
std::cerr << glCheckFramebufferStatus(GL_FRAMEBUFFER) << "\nFramebuffer failed to generate! 0\n";
}
unbindFrameBuffer();
}
FrameBuffer::~FrameBuffer()
{
if (fbo != NULL)
glDeleteFramebuffers(1, &fbo);
if (colorTexture != NULL)
glDeleteTextures(1, &colorTexture);
if (depthBuffer != NULL)
glDeleteRenderbuffers(1, &depthBuffer);
if (depthTexture != NULL)
glDeleteTextures(1, &depthTexture);
}
void FrameBuffer::createFrameBuffer(){
glGenFramebuffers(1, &fbo);
}
void FrameBuffer::createTextureAttachment(int width, int height){
glGenTextures(1, &colorTexture);
glBindTexture(GL_TEXTURE_2D, colorTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, GL_RGBA, 0, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTexture, 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE){
std::cerr << glCheckFramebufferStatus(GL_FRAMEBUFFER) << "\nFramebuffer failed to generate! 1\n";
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void FrameBuffer::createDepthTextureAttachment(int width, int height){
glGenTextures(1, &depthTexture);
glBindTexture(GL_TEXTURE_2D, depthTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, width, height, GL_DEPTH_COMPONENT, 0, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTexture, 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE){
std::cerr << glCheckFramebufferStatus(GL_FRAMEBUFFER) << "\nFramebuffer failed to generate! 2\n";
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void FrameBuffer::createDepthBufferAttachment(int width, int height){
glGenRenderbuffers(1, &depthBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE){
std::cerr << glCheckFramebufferStatus(GL_FRAMEBUFFER) << "\nFramebuffer failed to generate! 3\n";
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void FrameBuffer::bindFrameBuffer( int width, int height){
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glViewport(0, 0, width, height);
}
void FrameBuffer::unbindFrameBuffer(){
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, DisplayManager::getWidth(), DisplayManager::getHeight());
}
glCheckFrameBufferStatus returns GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
at both checks. The same happens with the createDepthTextureAttachment()
Neither one seems to not work
createDepthBufferAttachment() works fine.
More info:
Yes, indeed I'm actually giving width and height to the function, they are both 1024.
I've tried changing the GL_RGBA to GL_RGB, and Tried different sizes of GL_DEPTH_COMPONENT too.
At the moment I'm intending on using only 1 texture, not all 3 functions.
I don't know if it matters but SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); is set.
I've also tried glFramebufferTexture() function instead.
Thank you in advance!
The order of arguments in your glTexImage2D() calls is wrong. Looking at the first one:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, GL_RGBA, 0, GL_UNSIGNED_BYTE, NULL);
Comparing that to the function definition:
void glTexImage2D(
GLenum target,
GLint level,
GLint internalFormat,
GLsizei width,
GLsizei height,
GLint border,
GLenum format,
GLenum type,
const GLvoid* data);
you can see that the 6th argument is the border width, and the 7th is the format. You have those two inverted. The call should be:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
The same thing applies to the other call.
Anytime you have problems getting your OpenGL code working, I strongly recommend to call glGetError(). It would quickly tell you that there are errors from these calls.

OpenGL framebuffer resizeble texture

I'm using single color rendering in frame buffer
glGenFramebuffersEXT(1, &frontFramebufferId);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frontFramebufferId);
glGenTextures(1, &frontTextureId);
glBindTexture(GL_TEXTURE_2D, frontTextureId);
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);
glBindTexture(GL_TEXTURE_2D, frontTextureId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, frameStride, frameHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frontFramebufferId);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, frontTextureId, 0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
When I'm resizing window it's gives me black color.
Resizing function:
glViewport(0, 0, frameStride, frameHeight);
glBindTexture(GL_TEXTURE_2D, frontTextureId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, frameStride, frameHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frontFramebufferId);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, frontTextureId, 0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
It's necessary to use glFramebufferTexture2DEXT function on resize event? Or what is the problem? I'm using Nvidia's Cg framework.

copy opengl main framebuffer to a fbo

I want to copy the opengl main framebuffer to a fbo, which attach two texture object. then I want transfer the color buffer and depth buffer to the two texture object. I use glbiltframebuffer,but the texure is black, what is right way? my code :
// Create the FBO
glGenFramebuffers(1, &m_fbo);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo);
// Create textures
glGenTextures(1, &m_colorTexture);
glGenTextures(1, &m_depthTexture);
// color texture
glBindTexture(GL_TEXTURE_2D, m_colorTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, Width, Height, 0, GL_RGB, GL_FLOAT, NULL);
glFramebufferTexture2(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_colorTexture, 0);
// depth texture
glBindTexture(GL_TEXTURE_2D, m_depthTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, Width, Height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glBindTexture(GL_TEXTURE_2D, 0);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_depthTexture, 0);
GLenum Status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (Status != GL_FRAMEBUFFER_COMPLETE) {
printf("error, status: 0x%x\n", Status);
return false;
}
// restore default FBO
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
//copy the main framebuffer to FBO
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo);
glBlitFramebuffer(0, 0, Width, Height, 0, 0, Width, Height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
GLenum error = glGetError();
`
I solved it, the code is right. Error occurred in other place, I am sorry.
But I has been nagged by the bilt speed. I copy the main framebuffer to the fbo every frame. but it seems that the frame rate down a lot. can every one give some suggestion.

Using FBO to render YUV data

I was able to render YUV image on the screen using shaders.
To improve performance I want to use FBO. But I am not able to do it.
My initialization code is as below
void opengl_init(int w, int h) {
glGenFramebuffers(1, &framebuffer);
checkGlError("glGenFramebuffers");
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
checkGlError("glBindFramebuffer");
glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &gYTexture);
glBindTexture(GL_TEXTURE_2D, gYTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, FRAME_WIDTH, FRAME_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, 0);
glGenRenderbuffers(1, &colorbuffer);
checkGlError("glGenRenderbuffers");
glBindRenderbuffer(GL_RENDERBUFFER, colorbuffer);
checkGlError("glBindRenderbuffer");
glRenderbufferStorage(GL_RENDERBUFFER,
GL_RGB565, FRAME_WIDTH, FRAME_HEIGHT);
checkGlError("glRenderbufferStorage");
glFramebufferRenderbuffer(GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0,
GL_RENDERBUFFER, depthbuffer);
checkGlError("glFramebufferRenderbuffer");
glFramebufferTexture2D(GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
gYTexture, 0);
checkGlError("glFramebufferTexture2D");
int status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
printf("Framebuffer is not complete: *status* = %d", status);
if (status != GL_FRAMEBUFFER_COMPLETE) {
printf("Framebuffer is not complete: *status* = %d", status);
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
checkGlError("glBindFramebuffer");
glGenBuffers(1, ioBuf);
checkGlError("glGenBuffers");
glActiveTexture(GL_TEXTURE1);
glGenTextures(1, &gUTexture);
glBindTexture(GL_TEXTURE_2D, gUTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glActiveTexture(GL_TEXTURE2);
glGenTextures(1, &gVTexture);
glBindTexture(GL_TEXTURE_2D, gVTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glViewport(0, 0, w, h);
checkGlError("glViewport");
}
I render my frame using the below code
void opengl_renderframe(void *yuvbuf,int framewidth, int frameheight) {
static void *ubuf, *vbuf;
ubuf = (char *)yuvbuf + (framewidth * frameheight);
vbuf = (char *)ubuf + ((framewidth * frameheight) / 4);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
checkGlError("glBindFramebuffer");
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
checkGlError("glClearColor");
glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
checkGlError("glClear");
glUseProgram(gProgram);
checkGlError("glUseProgram");
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, gYTexture);
glBindBuffer(GL_ARRAY_BUFFER, ioBuf);
checkGlError("glBindBuffer");
glBufferData(GL_ARRAY_BUFFER, (FRAME_WIDTH * FRAME_HEIGHT) , yuvbuf, GL_STATIC_DRAW);
checkGlError("glBufferData");
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, FRAME_WIDTH, FRAME_HEIGHT, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NULL);
checkGlError("glTexImage2D");
glBindBuffer(GL_ARRAY_BUFFER, 0);
checkGlError("glBindBuffer");
glUniform1i(Ysamp, 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, gUTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, framewidth/2, frameheight/2, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, ubuf );
glUniform1i(Usamp, 1);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, gVTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, framewidth/2, frameheight/2, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, vbuf );
glUniform1i(Vsamp, 2);
glVertexAttribPointer(gvPositionHandle, 2, GL_FLOAT, GL_FALSE, 0, gTriangleVertices);
checkGlError("glVertexAttribPointer");
glEnableVertexAttribArray(gvPositionHandle);
checkGlError("glEnableVertexAttribArray");
glVertexAttribPointer(gaTextureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, gTriangleVertices2);
checkGlError("glVertexAttribPointer");
glEnableVertexAttribArray(gaTextureCoordHandle);
checkGlError("glEnableVertexAttribArray");
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
checkGlError("glDrawArrays");
glBindFramebuffer(GL_FRAMEBUFFER, 0);
checkGlError("glBindFramebuffer 0");
}
my fragment shader to render only Y data is as below
static const char gGrayScaleFragmentShader[] =
"precision mediump float;\n"
"varying vec2 vTextureCoord;\n"
"uniform sampler2D sTexture;\n"
"void main() {\n"
" gl_FragColor = texture2D(sTexture, vTextureCoord);\n"
"}\n";

OpenGL Render to texture (FBO) does not work

I'm trying to use FBO to render to texture and then display the texture, but all I get is a black rectangle. My code is:
Initialization:
#include <GL/glew.h>
#include <GL/gl.h>
#include <GL/glext.h>
#include <assert.h>
// ...
GLuint fbo_, rbo_, tex_;
glGenFramebuffers(1, &fbo_);
glBindFramebuffer(GL_FRAMEBUFFER, fbo_);
glGenRenderbuffers(1, &rbo_);
glBindRenderbuffer(GL_RENDERBUFFER, rbo_);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width_, height_);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbo_);
glGenTextures(1, &tex_);
glBindTexture(GL_TEXTURE_2D, tex_);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width_, height_, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glGenerateMipmap(GL_TEXTURE_2D);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex_, 0);
assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
Render to the FBO:
glPushAttrib(GL_VIEWPORT_BIT);
glViewport(0, 0, width_, height_);
glBindFramebuffer(GL_FRAMEBUFFER, fbo_);
//draw stuff
glPopAttrib();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
Use the texture (the problem is probably in the code above, because if I just use some static texture, the code below works):
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex_);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex3f(x_, y_, 0);
glTexCoord2f(width_, 0);
glVertex3f(x_ + width_, y_, 0);
glTexCoord2f(width_, height_);
glVertex3f(x_ + width_, y_ + height_, 0);
glTexCoord2f(0, height_);
glVertex3f(x_, y_ + height_, 0);
glEnd();
Could you help me spot the problem?
Make sure the texture you attach is complete if you're going to rely on the default texture environment.
I had the same problem and used genpfault's advice to create a complete texture. Unfortunately, I do not have enough reputation to add a comment so I just added this answer here. Still, the code below may save you some time:
// generate full viewport texture
glGenTextures(1, &fb_tex);
glBindTexture(GL_TEXTURE_2D, fb_tex);
// IMPORTANT: texture must be COMPLETE (mipmaps must be specified..
// or the following parameters can be used if there are none)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
glTexImage2D(
GL_TEXTURE_2D,
0,
GL_RGBA,
width,
height,
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
NULL
);
The only thing I changed in my original code was two add the two lines with glTexParameteri. The parameters can be changed depending on the amount of mipmaps you want/have.