• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Ashaira

Rendering to FBO and Post Processing Quad

1 post in this topic

so i thought i understood how FBO work but it seems not. ive been trying to render to a FBO and then using the texture to render a quad that i will use for post processing effects. I went through several tutorials and everything "seems" right but then again it always does.

This is how i implemented my FBO in the scene manager constructor

[CODE]
glGenRenderbuffers(1, &RBO); // Generate one render buffer and store the ID in fbo_depth
glBindRenderbuffer(GL_RENDERBUFFER, RBO); // Bind the fbo_depth render buffer
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, 1024, 780); // Set the render buffer storage to be a depth component, with a width and height of the window
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, RBO); // Set the render buffer of this buffer to the depth buffer
glBindRenderbuffer(GL_RENDERBUFFER, 0); // Unbind the render buffer
glGenTextures(1, &FBO_Texture); // Generate one texture
glBindTexture(GL_TEXTURE_2D, FBO_Texture); // Bind the texture fbo_texture
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1024, 780, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); // Create a standard texture with the width and height of our window
// Setup the basic texture parameters
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// Unbind the texture
glBindTexture(GL_TEXTURE_2D, 0);
glGenFramebuffers(1, &FBO); // Generate one frame buffer and store the ID in fbo
glBindFramebuffer(GL_FRAMEBUFFER, FBO); // Bind our frame buffer
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, FBO_Texture, 0); // Attach the texture fbo_texture to the color buffer in our frame buffer
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, RBO); // Attach the depth buffer fbo_depth to our frame buffer
/*switch (glCheckFramebufferStatus(GL_FRAMEBUFFER)){
case GL_FRAMEBUFFER_COMPLETE:
std::cout << "Complete." << std::endl;
break;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
std::cout << "Incomplete Attachment" << std::endl;
break;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
std::cout << "Incomplete Missing Attachment" << std::endl;
break;
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
std::cout << "Not all attached images have the same width and height." << std::endl;
break;
case GL_FRAMEBUFFER_UNSUPPORTED:
std::cout << "Framebuffer Unsupported" << std::endl;
break;
}*/
glBindFramebuffer(GL_FRAMEBUFFER, 0);
[/CODE]

this should be ok as i have used glCheckFramebufferStatus and it didnt return any errors.

now for the rendering. This is the draw call in my scene manager (which works fine if i remove the FBO so the error cant be in a diff place)

[CODE]
glViewport ( 0, 0, esContext->width, esContext->height );
// Clear the color buffer
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
for(int j=0; j<Resources->ShaderNum ; j++)
{
userData->programObject = Resources->Programs[j];
glUseProgram ( Resources->Programs[j] );
for(int i=0; i<ObjectsLoaded; i++)
{
if(GameObjects[i]->shader == j+1)
{
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);

if(Resources->Shaders[j].Culling && Culling == false)
{
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
Culling = true;
}
if(Resources->Shaders[j].Blending && Blending == false)
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Blending = true;
}
glBindFramebuffer(GL_FRAMEBUFFER, FBO);
GameObjects[i]->Draw(esContext);
if(Culling == true)
{
glDisable(GL_CULL_FACE);
Culling = false;
}
if(Blending == true)
{
glDisable(GL_BLEND);
Blending = false;
}
}
}
}
eglSwapBuffers ( esContext->eglDisplay, esContext->eglSurface );
glBindFramebuffer(GL_FRAMEBUFFER, 0); // unbind
// Clear the color buffer
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
userData->programObject = Resources->PostProcessingPrograms[0];
Quad->Draw(esContext);
[/CODE]

and this is what the post processing quad draw call looks like

[CODE]
GLfloat vVertices[] = { 512.0f, 390.0f, 0.0f,
-512.0f, 390.0f, 0.0f,
-512.0f, -390.0f, 0.0f,
512.0f, -390.0f, 0.0f};
GLfloat vTexCoord[] = { 1.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f};
// Use the program object
glUseProgram ( userData->programObject );
glBindAttribLocation ( userData->programObject, 0, "vPosition" );
glBindAttribLocation ( userData->programObject, 1, "a_texCoord" );
glActiveTexture(GL_TEXTURE0 + 1);
Texture_Uniform_Loc = glGetUniformLocation ( userData->programObject, "texture1" );
glBindTexture(GL_TEXTURE_2D, Scene->FBO_Texture);
glUniform1i(Texture_Uniform_Loc, 1);
// Load the vertex data
glVertexAttribPointer ( 0, 3, GL_FLOAT, GL_FALSE, 0, vVertices );
glEnableVertexAttribArray ( 0 );
glVertexAttribPointer ( 1, 3, GL_FLOAT, GL_FALSE, 0, vTexCoord );
glEnableVertexAttribArray ( 1 );
glDrawArrays ( GL_TRIANGLES, 0, 3 );
eglSwapBuffers ( esContext->eglDisplay, esContext->eglSurface );
[/CODE]

there are no errors but everything on the screen is just black.

i tried making the quad smaller reversing the vertex order (Clockwise and CounterClockwise) i tried using the perspective matrix and rotated around to try and find the quad in case i misplaced it but nothing works the screen just stays black. im pretty sure im simply not rendering to the FBO right or im not applying the texture to the quad right but im not sure what i did wrong.

Any help would be greatly appreciated.
0

Share this post


Link to post
Share on other sites
Hi,

I also implemented FBOs in my game yesterday (but it is not tested yet [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img] ).
My source looks like this:
[CODE]
//Init
glGenFramebuffers(1, &frameBuffer);
glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);
glGenRenderbuffers(1, &depthBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, size, size);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer);
glGenTextures(1, &colorBuffer);
glBindTexture(GL_TEXTURE_2D, colorBuffer);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
if(resizedDisplay) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glGenerateMipmap(GL_TEXTURE_2D);
}else{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
//Render into
glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
glDrawBuffer(GL_COLOR_ATTACHMENT0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, size, size);
//Render from
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, colorBuffer);
[/CODE]


There are some differences between our codes:
1. My program first creates the Framebuffer and than the Renderbuffers.
2. Your texture is 1024x780 but non square textures are not supported on every hardware (it is a extension).
3. My program clears the Renderbuffers after it has bound them

And if nothing helps, here is a nice tutorial about FBOs: [url="http://wiki.delphigl.com/index.php/Tutorial_Framebufferobject"]http://wiki.delphigl...amebufferobject[/url]
It is German but I think you can read the source code at least.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0