portable FBO code

Sage
Posts: 1,403
Joined: 2005.07
Post: #1
So I wrote a little paint program that does everything on the GPU with FBOs

it only works on my computer :/

I am hoping that someone who has written FBO on a diff card or that has tested it on other computers would be able to post some or point out anything I have done wrong.

I did write all this code with the opengl spec as reference so I dont see whats wrong... anyway thanks in advance for great advice I always seem to get on this forum Grin


Code:
    // set up the FBO
    glGenFramebuffersEXT(1, &graphicsFBO);
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, graphicsFBO);
    
    glGenTextures(1, &graphicsImage);
    glBindTexture(GL_TEXTURE_2D, graphicsImage);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
    
    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, graphicsImage, 0);
    printf("FBO STATUS: %d\n", glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) == GL_FRAMEBUFFER_COMPLETE_EXT);
    
    glClear(GL_COLOR_BUFFER_BIT);
    
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

Code:
- (void)mouseDown:(NSEvent*)event
{
    mouseLocation = [[[self window] contentView] convertPoint:[event locationInWindow] toView:self];
    mouseLocation.y = [self bounds].size.height-mouseLocation.y;
    
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, graphicsFBO);
    
    glColor3f(1, 1, 1);
    glBindTexture(GL_TEXTURE_2D, paintbrush_texture);
    
    glPushMatrix();
    glTranslatef(-paintbrush_visual_size/2.0, -paintbrush_visual_size/2.0, 0);
    glTranslatef(mouseLocation.x, mouseLocation.y, 0);
    DRAW_GL_TEXTURE_QUAD(paintbrush_visual_size);
    glPopMatrix();
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
use RGBA for your texture's internal format. I know of no hardware that can render to or from an RGB texture.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #3
Well it works ok on a ATI Radeon X1900, but changing the FBO to RGBA fixed it for other people, thanks so much!

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #4
All hardware that supports FBO can render to and texture from RGBA8 and RGB8.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
Clearly not Wink
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #6
If you have a reproducible case where it doesn't work, let's have it, along with the config info.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Free, Portable Graphics loading library/Header Jones 5 3,094 Feb 7, 2006 12:15 PM
Last Post: Zekaric