openGL n00b looking for FBO drawing examples or direction

Nibbie
Posts: 4
Joined: 2009.04
Post: #1
Hi --

I'm still in the steep slope of the openGL ES learning curve, although I have managed to draw a nice shape (over 2000 triangles!) and wrap it in a texture.

But now I want to modify the texture, specifically, I want to add a bunch of small markers at setup time (not each frame draw), and then wrap the shape with the modified texture. The locations of the markers will differ from time to time, they are loaded from my server dynamically before setup.

The main texture is 1024 x 1024, and the small markers might be 32x32 or even 16x16.

I have read enough to think that what I need to do is to create and then draw to a framebuffer object, and then use that, or a texture made from that, as the texture to wrap my shape.

Does anyone know where I might find some example code that does this, or a tutorial that I can study that covers this?

Any direction greatly appreciated!
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #2
Apple provides FBO sample code for OpenGL. The concepts are exactly the same in ES.

See also Nvidia's sample code and the FBO Wiki page.
Quote this message in a reply
Nibbie
Posts: 4
Joined: 2009.04
Post: #3
arekkusu Wrote:Apple provides FBO sample code for OpenGL. The concepts are exactly the same in ES.

See also Nvidia's sample code and the FBO Wiki page.


arekkusu --

thanks! I'm sure I have enough there to get this done.

Actually, I'm part way there already, but my object looks all white, so I'm probably just missing a few key things.

have a great day
Quote this message in a reply
Nibbie
Posts: 4
Joined: 2009.04
Post: #4
Hi

Wow, I learned a lot from the links, in fact I *think* I have a strategy in place, but alas I'm getting the "all white texture". Here is the code, I call setupFbo() once, before I setup things like the matrtix mode and glOrtho, and then I call renderFbo() right after that.

In drawView(), I'm just trying to use the texture (fboTexture) in place of the bgWorldMap texture, which is 1024 x 1024. My idea is that if I can get this to work, I can add to the renderFbo function to put in the other small textures that I need to add.

So, if anyone can see something dumb that I'm doing, or missing, that would cause an all-white texture I would appreciate it!

The setup code, called once:

BTW if I un-comment out the glEnable(GL_DEPTH) I get all black.
Code:
GLuint extFBO;
GLuint depthBuffer;
GLuint fboTexture;

-(void)setupFBO{
    
    glGenFramebuffersOES(1, &extFBO);
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, extFBO);
    
    glGenRenderbuffersOES(1, &depthBuffer);
    glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthBuffer);
    glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, 1024, 1024);
    glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthBuffer);
    
//    glEnable(GL_DEPTH_TEST);
    
    glGenTextures(1, &fboTexture);
    glBindTexture(GL_TEXTURE_2D, fboTexture);
    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_RGBA,  1024, 1024, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
    glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, fboTexture, 0);
    
    GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES);
    if( status != GL_FRAMEBUFFER_COMPLETE_OES ){
        NSLog(@"bad setupFBO status");
    }
    
}


The render code, called once:

Code:
-(void)renderFBO{

    const GLfloat vertices[] = {
        -512., -512.,
        512., -512.,
        -512.,  512.,
        512.,  512.,
    };
    
    glViewport(0,0,1024, 1024);
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, extFBO);        // actually already bound, above
//    glPushAttrib(GL_VIEWPORT_BIT);
    
    // Render as normal here
    // output goes to the FBO and it’s attached buffers
    glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();    
    
//    glBlendFunc(GL_SRC_ALPHA, GL_ZERO);        // GL_ZERO or GL_ONE
    glActiveTexture(GL_TEXTURE0);
    glEnable(GL_TEXTURE_2D);    
    glEnableClientState(GL_VERTEX_ARRAY);
    
    // draw the background texture to the fbo
    glBindTexture(GL_TEXTURE_2D, bgWorldMap);
    glGenerateMipmapOES(GL_TEXTURE_2D);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glVertexPointer(2, GL_FLOAT, 0, vertices);
    glColor4f(1, 1, 1, 1);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);    
    
//    glPopAttrib();
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
    glDisable(GL_TEXTURE_2D);
//    glDisable(GL_DEPTH_TEST);
    
}

And then in drawView(), this works, shows the map

Code:
glBindTexture(GL_TEXTURE_2D, bgWorldMap);    // this was working
    // glBindTexture(GL_TEXTURE_2D, fboTexture);

And this does not work, shows all white:

Code:
//    glBindTexture(GL_TEXTURE_2D, bgWorldMap);    // this was working
    glBindTexture(GL_TEXTURE_2D, fboTexture);

thanks!!!!!!
Quote this message in a reply
Nibbie
Posts: 2
Joined: 2009.10
Post: #5
did you ever find a solution to your issue with the white texture?
Quote this message in a reply
Apprentice
Posts: 14
Joined: 2009.06
Post: #6
auptown Wrote:
Code:
-(void)renderFBO{

    const GLfloat vertices[] = {
        -512., -512.,
        512., -512.,
        -512.,  512.,
        512.,  512.,
    };

I think this is the main problem, the vertex are always in 0.0 to 1.0 range, 512.0 gets out of range, and that's why you get a black or white texture
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL Cube drawing: VBOs, instanced geometry, octrees Symbol$ 5 9,057 Dec 23, 2011 01:43 PM
Last Post: Skorche
  Drawing menu versus drawing game johncmurphy 4 4,280 Jan 6, 2010 09:14 AM
Last Post: AnotherJake
  OpenGL ES : Drawing Text... savage 8 10,040 Jan 4, 2010 08:59 PM
Last Post: alerus
  Drawing shapes opengl es jjslay 2 4,082 Aug 14, 2009 11:07 AM
Last Post: jjslay
  OpenGL sprites - please help this n00b Gillissie 15 8,700 Mar 15, 2009 12:22 AM
Last Post: AnotherJake