OpenGL: Framebuffer, incomplete texture attachment - c++

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.

Related

Why I can't bind max size texture to framebuffer

I use this code to bind the texture to a frame buffer, in my computer, now the w=h=32768
int w,h;
glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &w);
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &h);
w = h = std::min(w, h);
unsigned int FBO;
glGenFramebuffers(1, &FBO);
glBindFramebuffer(GL_FRAMEBUFFER, FBO);
unsigned int TBO;
glGenTextures(1, &TBO);
glBindTexture(GL_TEXTURE_2D, TBO);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, 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);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, TBO, 0);
unsigned int RBO;
glGenRenderbuffers(1, &RBO);
glBindRenderbuffer(GL_RENDERBUFFER, RBO);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, w, h);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, RBO);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
printf("%x\n", glCheckFramebufferStatus(GL_FRAMEBUFFER));
std::cout << "ERROR::FRAMEBUFFER:: Framebuffer is not complete!" << std::endl;
exit(1);
}
If I do so, glCheckFramebufferStatus(GL_FRAMEBUFFER) is return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
Then I make variable w=h=8192 (the variable also can't be 16384), the code can work well.
Is there some wrong with my code?
Update 1:
I find the max_value is 16384 if using my Integrated graphics, and it's 32768 in my Nvidia GPU.
But now I can't recur the result. I guess it's also linked with the state of my graphics, maybe my graphics don't have enough memory at that time?
Update 2:
Now I loop the same rendering process, the GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT is return again after several rendering.

How to render anti-aliased image to a texture (and then write to PNG)?

I'd like to use the "render to texture" paradigm to write a .png screenshot of my OpenGL 3D rendering. I have it working without multi-sampling, but I'm struggling to get an anti-aliased image.
First of all, is this possible?
Second, what is the right combination of API calls?
(meta third question, how can I better debug this? glCheckFramebufferStatus is clearly not enough).
Here's what I'm working with:
// https://stackoverflow.com/questions/7402504/multisampled-render-to-texture-in-ios
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA4, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
GLuint resolved_framebuffer, resolvedColorRenderbuffer;
glGenFramebuffers(1, &resolved_framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, resolved_framebuffer);
glGenRenderbuffers(1, &resolvedColorRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, resolvedColorRenderbuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
GLuint framebuffer;
glGenFramebuffers(1, &framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
GLuint colorRenderbuffer, depthRenderbuffer;
glGenRenderbuffers(1, &colorRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_RGBA8, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRenderbuffer);
glGenRenderbuffers(1, &depthRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH_COMPONENT16, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRenderbuffer);
assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
glBindFramebuffer( GL_FRAMEBUFFER, framebuffer );
glClearColor(background_color(0), background_color(1), background_color(2), 0.f);
glClear(GL_COLOR_BUFFER_BIT);// | GL_DEPTH_BUFFER_BIT);
draw_scene();
glBindFramebuffer( GL_READ_FRAMEBUFFER, framebuffer );
glBindFramebuffer( GL_DRAW_FRAMEBUFFER, resolved_framebuffer );
// https://forum.juce.com/t/ios-8-getting-the-demo-building/13570/20
glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
// ^--- this is throwing `GL_INVALID_OPERATION`
GLubyte* pixels = (GLubyte*)calloc(width*height*4,sizeof(GLubyte));
glReadPixels(0, 0,width, height,GL_RGBA, GL_UNSIGNED_BYTE, pixels);
writePNG(pixels);
Currently I'm getting a blank image and glBlitFramebuffer is throwing GL_INVALID_OPERATION. Apparently this error can correspond to many things, and I'm not sure which is applying. My buffers seem "good" according to glCheckFramebufferStatus.
This question has been asked in similar forms before:
Cannot render to texture with multisampling
Multisampled render to texture in ios
But none of the answers have lead to a complete working example. I would love to find/create a minimal example of this.
The tutorial at https://learnopengl.com/Advanced-OpenGL/Anti-Aliasing basically had what I needed. The working solution is:
unsigned int framebuffer;
glGenFramebuffers(1, &framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
// create a multisampled color attachment texture
unsigned int textureColorBufferMultiSampled;
glGenTextures(1, &textureColorBufferMultiSampled);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, textureColorBufferMultiSampled);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGBA, width, height, GL_TRUE);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, textureColorBufferMultiSampled, 0);
// create a (also multisampled) renderbuffer object for depth and stencil attachments
unsigned int rbo;
glGenRenderbuffers(1, &rbo);
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH24_STENCIL8, width, height);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbo);
assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
// configure second post-processing framebuffer
unsigned int intermediateFBO;
glGenFramebuffers(1, &intermediateFBO);
glBindFramebuffer(GL_FRAMEBUFFER, intermediateFBO);
// create a color attachment texture
unsigned int screenTexture;
glGenTextures(1, &screenTexture);
glBindTexture(GL_TEXTURE_2D, screenTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, screenTexture, 0); // we only need a color buffer
assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
draw_scene();
glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, intermediateFBO);
glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
glBindFramebuffer(GL_FRAMEBUFFER, intermediateFBO);
GLubyte* pixels = (GLubyte*)calloc(width*height*4,sizeof(GLubyte));
glReadPixels(0, 0,width, height,GL_RGBA, GL_UNSIGNED_BYTE, pixels);
writePNG(pixels);
It seems there're at least two errors in the code in the original question:
The framebuffer should have a multisample texture attached, not a renderbuffer (glFramebufferTexture2D(... GL_TEXTURE_2D_MULTISAMPLE instead of glRenderbufferStorageMultisample)
Must call glBindFramebuffer(GL_FRAMEBUFFER, intermediateFBO); after blitting and before glReadPixels

How to get texelFetchOffset to wrap around?

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.

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.

How Can I Render To One Face Of An OpenGL Cubemap texture

I'm making a Cube map render target class.
I already have a 2D one that works fine. But for this cube map render target class I want to be able to render to a specific face as i wish. Maybe I want to render circles on the "X+" face but triangles in the "Y+" face.
This is what my class looks like
class CRenderTarget
{
private:
//frame buffer to render on
unsigned m_uifboHandle;
//depth stencil
unsigned m_uiDepthStencilHandle;
//the texture we will render on
unsigned m_uiTextureHandle;
public:
CCubeRenderTarget( void );
~CCubeRenderTarget( void );
void Create( unsigned uiHeightWidth = 512,
int iInternalFormat = 0x1908 ); //GL_RGBA
void Bind( void );
void UnBind( void );
}
This is how my create function looks like
void Create( unsigned uiHeightWidth, int iInternalFormat )
{
//generate our variables
glGenFramebuffers(1, &m_uifboHandle);
glGenRenderbuffers(1, &m_uiDepthStencilHandle);
glGenTextures(1, &m_uiTextureHandle);
// Initialize FBO
glBindFramebuffer( GL_FRAMEBUFFER, m_uifboHandle);
glBindTexture( GL_TEXTURE_CUBE_MAP, m_uiTextureHandle);
// Pre-allocate the correct sized cube map
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, iInternalFormat, uiHeightWidth, uiHeightWidth, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, iInternalFormat, uiHeightWidth, uiHeightWidth, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, iInternalFormat, uiHeightWidth, uiHeightWidth, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, iInternalFormat, uiHeightWidth, uiHeightWidth, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, iInternalFormat, uiHeightWidth, uiHeightWidth, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, iInternalFormat, uiHeightWidth, uiHeightWidth, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
// Must attach texture to framebuffer. Has Stencil and depth
glBindRenderbuffer(GL_RENDERBUFFER, m_uiDepthStencilHandle);
glRenderbufferStorage(GL_RENDERBUFFER, /*GL_DEPTH_STENCIL*/GL_DEPTH24_STENCIL8, uiHeightWidth, uiHeightWidth );
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_uiDepthStencilHandle);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_uiDepthStencilHandle);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
this is what my bind function looks like
void Bind( void )
{
glBindFramebuffer( GL_FRAMEBUFFER, m_uifboHandle );
}
//this is what my unbind function looks like
void Unbind( void )
{
glBindFramebuffer( GL_FRAMEBUFFER, 0 );
}
I done tons of research for the past week. I can't seem to find a way that i can just some how instead of binding my entire cube map just bind maybe 1 face of my cube map. which is my overall goal. I know that in DirectX you can by just grabbing the 6 faces and manually handling them but how can i manually handle each face on an openGL cube map?
Having bound the framebuffer, you need to specify what level of the texture should be targetted. It should be something like this:
glBindFramebuffer( GL_FRAMEBUFFER, m_uifboHandle );
glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X, m_uiTextureHandle, 0);