• 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
HatiEth

Problem/Question regarding FBOs and Render to Texture

3 posts in this topic

Hi, I have a rather odd problem regarding my code I've implemented FBO, but have got a rather odd problem with my code.
I've implemented it twice, where both implementations should work (atleast from my point of view , but I'm properly just code-blind)

The not working code is:
[CODE]
void CParticleSystemMouse::generate( void )
{
glGenFramebuffers(1, &m_frontBuffer);
glGenFramebuffers(1, &m_backBuffer);
glBindFramebuffer(1, m_frontBuffer);

glGenTextures(1, &m_frontParticles);
glBindTexture(GL_TEXTURE_2D,m_frontParticles);
int AM = m_width*m_height*4; //amount of data
srand(0);
int r =0;
char* data = new char[AM];
for(int i = 0; i < AM; i+=4) {
r = rand()%10;
//std::cout << r << std::endl;
data[i+0] = 0; //x velo
data[i+1] = 0; //y velo
data[i+2] = 255; //~
data[i+3] = (rand()%10)<5?255:0; // is particle
}
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_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,m_width,m_height,0,GL_RGBA,GL_UNSIGNED_BYTE,(GLvoid*)data);
glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,m_frontParticles,0);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(status != GL_FRAMEBUFFER_COMPLETE)
std::cout << "FBO("<<m_frontBuffer <<") incomplete!" << std::endl;
glBindTexture(GL_TEXTURE_2D,0);
glBindFramebuffer(GL_FRAMEBUFFER,0);
glBindFramebuffer(GL_FRAMEBUFFER,m_backBuffer);
glGenTextures(1, &m_backParticles);
glBindTexture(GL_TEXTURE_2D,m_backParticles);
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_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,m_width,m_height,0,GL_RGBA,GL_UNSIGNED_BYTE,(GLvoid*)0);
glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,m_backParticles,0);
status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(status!= GL_FRAMEBUFFER_COMPLETE)
std::cout << "FBO("<<m_frontBuffer <<") incomplete!" << std::endl;
glBindTexture(GL_TEXTURE_2D,0);
glBindFramebuffer(GL_FRAMEBUFFER,0);
delete [] data;
m_calcShader = new CShader(NULL,NULL,"particlesystemmouse.frag");
swapBuffers();
}
[/CODE]
It is generating the FBOs successfully - I can render to them but the texture is not actually saved after rendering to it.

the swapBuffers function is:
[CODE]
void CParticleSystemMouse::swapBuffers() {

GLuint tmp = m_frontParticles;
m_frontParticles = m_backParticles;
m_backParticles = tmp;

tmp = m_frontBuffer;
m_frontBuffer = m_backBuffer;
m_backBuffer = tmp;
}
[/CODE]

I then copied the generate code from another class where it was working correctly, but I have no clue why it does, and the problem is localized in the generate function that I can confirm so far.

[CODE]void CParticleSystemMouse::generate( void )
{
//Gen firstbuffer
glGenFramebuffers(1,&m_frontBuffer);
glGenFramebuffers(1,&m_backBuffer);
//Bind firstbuffer
glBindFramebuffer(GL_FRAMEBUFFER,m_frontBuffer);

GLuint depthBuffer;
glGenRenderbuffers(1,&depthBuffer);
glBindRenderbuffer(GL_RENDERBUFFER,depthBuffer);

glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_width,m_height);

glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,depthBuffer);

int AM = m_width*m_height*4;

srand(0);
//srand(time(NULL));

char* data = new char[AM];
int r = 0;
for(int i = 0;i<AM;i+=4){
r = rand() % 10;
if(r<5) {
data[i+0] = 0;
data[i+1] = 0;
data[i+2] = 255;
data[i+3] = 255;
}
else {
data[i+0] = 0;
data[i+1] = 0;
data[i+2] = 0;
data[i+3] = 0;
}
}
/*bool swapSet=false;
for(int i=0;i<AM;i+=4) {
data[i+0] = 0;
data[i+1] = swapSet?255:0;
data[i+2] = 0;
data[i+3] = 255;
swapSet=!swapSet;
}*/

// Texture0
glGenTextures(1,&m_frontParticles);
glBindTexture(GL_TEXTURE_2D,m_frontParticles);

glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,m_width,m_height,0,GL_RGBA,GL_UNSIGNED_BYTE,(GLvoid*)data);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);

glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,m_frontParticles,0);

GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);

if(status != GL_FRAMEBUFFER_COMPLETE)
std::cout << "[Error] FBO " << m_frontBuffer << " incomplete!" << std::endl;


glBindTexture(GL_TEXTURE_2D,0);
glBindRenderbuffer(GL_RENDERBUFFER,0);
glBindFramebuffer(GL_FRAMEBUFFER,0);
//Gen backBuffer

glBindFramebuffer(GL_FRAMEBUFFER,m_backBuffer);
depthBuffer = 0;
glGenRenderbuffers(1,&depthBuffer);
glBindRenderbuffer(GL_RENDERBUFFER,depthBuffer);

glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_width,m_height);

glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,depthBuffer);

// backTexture 0
glGenTextures(1,&m_backParticles);
glBindTexture(GL_TEXTURE_2D,m_backParticles);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,m_width,m_height,0,GL_RGBA,GL_UNSIGNED_BYTE,(GLvoid*)0);

//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);

glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,m_backParticles,0);

status = glCheckFramebufferStatus(GL_FRAMEBUFFER);

if(status != GL_FRAMEBUFFER_COMPLETE)
std::cout << "[Error] FBO " << m_backBuffer << " incomplete!" << std::endl;

m_calcShader = new CShader(NULL, NULL, "particlesystemmouse.frag");

delete [] data;

glBindFramebuffer(GL_FRAMEBUFFER,0);
glBindTexture(GL_TEXTURE_2D,0);
glBindRenderbuffer(GL_RENDERBUFFER,0);

swapBuffers();
}

[/CODE]

So, can someone explain me, what is going on, is there something I'm ignoring ?
(Just in case someone points to the render buffer, I've already commented them out in the [b]working[/b] generate code - ain't no change to the working state)
0

Share this post


Link to post
Share on other sites
In your non-working [i]generate[/i] function, you don't set the [i]GL_DEPTH_ATTACHMENT[/i] for either of the FBOs. Try setting those and see if that works.

Also, this:
[code]
glBindFramebuffer(1, m_frontBuffer);
[/code]

should be this:
[code]
glBindFramebuffer(GL_FRAMEBUFFER, m_frontBuffer);
[/code]
1

Share this post


Link to post
Share on other sites
[quote name='shacktar' timestamp='1326293712' post='4901650']
In your non-working [i]generate[/i] function, you don't set the [i]GL_DEPTH_ATTACHMENT[/i] for either of the FBOs. Try setting those and see if that works.[/quote]

RenderBuffers (including Depth-Buffers are not actually necessary for what I try to do - like i said in the last lines of my first post - i already tried if it was them by commenting them out in the working code which changed nothing on the working status)

[quote name='shacktar' timestamp='1326293712' post='4901650']
Also, this:
[code]
glBindFramebuffer(1, m_frontBuffer);
[/code]

should be this:
[code]
glBindFramebuffer(GL_FRAMEBUFFER, m_frontBuffer);
[/code]
[/quote]
Thanks, that was the issue, code-blindness :) - didn't saw it.
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