Jump to content
  • Advertisement
Sign in to follow this  
gltiich

Rendering to Texture results in blank screen

This topic is 3625 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I tried to wrap rendering to a texture over a default GLUT program from Dev-CPP glut/ogl devpacks. All I get is a white screen.... does anyone see why? Please help! :) Here's the source broken up; Initialization:

// buffers/texture stuff
const int SD = 512;

GLuint FBOTex;
GLuint FBO;
GLuint DepthBuffer, StencilBuffer;
GLenum AttchPoint[] = {GL_COLOR_ATTACHMENT0_EXT};

glGenFramebuffersEXT(1, &FBO);
glGenTextures(1, &FBOTex);
glGenRenderbuffersEXT(1, &DepthBuffer);
glGenRenderbuffersEXT(1, &StencilBuffer);

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FBO);

glBindTexture(GL_TEXTURE_2D, FBOTex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, SD, SD, 0, GL_RGBA, GL_INT, NULL);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, DepthBuffer);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, SD, SD);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, DepthBuffer);

glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, StencilBuffer);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_STENCIL_INDEX, SD, SD);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, StencilBuffer);

glDrawBuffers(1, AttchPoint);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, AttchPoint[0], GL_TEXTURE_2D, FBOTex, 0);

// lighting
const GLfloat light_ambient[]  = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[]  = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };

const GLfloat mat_ambient[]    = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[]    = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[]   = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };


//main
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);

glEnable(GL_TEXTURE_2D);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);

glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);

glLightfv(GL_LIGHT0, GL_AMBIENT,  light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE,  light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);

glMaterialfv(GL_FRONT, GL_AMBIENT,   mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE,   mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR,  mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);

glewInit();
//gInitTex(); <-- stuff above
glutMainLoop();

Render Loop:
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FBO);
glPushAttrib(GL_VIEWPORT_BIT | GL_COLOR_BUFFER_BIT);
glViewport(0, 0, SD, SD);
glDrawBuffer(AttchPoint[0]);

glColor3d(1,0,0);

glPushMatrix();
	glTranslated(-2.4,1.2,-6);
	glRotated(60,1,0,0);
	glRotated(a,0,0,1);
	glutSolidSphere(1,slices,stacks);
glPopMatrix();

glPushMatrix();
	glTranslated(0,1.2,-6);
	glRotated(60,1,0,0);
	glRotated(a,0,0,1);
	glutSolidCone(1,1,slices,stacks);
glPopMatrix();

glPushMatrix();
	glTranslated(2.4,1.2,-6);
	glRotated(60,1,0,0);
	glRotated(a,0,0,1);
	glutSolidTorus(0.2,0.8,slices,stacks);
glPopMatrix();

glPushMatrix();
	glTranslated(-2.4,-1.2,-6);
	glRotated(60,1,0,0);
	glRotated(a,0,0,1);
	glutWireSphere(1,slices,stacks);
glPopMatrix();

glPushMatrix();
	glTranslated(0,-1.2,-6);
	glRotated(60,1,0,0);
	glRotated(a,0,0,1);
	glutWireCone(1,1,slices,stacks);
glPopMatrix();

glPushMatrix();
	glTranslated(2.4,-1.2,-6);
	glRotated(60,1,0,0);
	glRotated(a,0,0,1);
	glutWireTorus(0.2,0.8,slices,stacks);
glPopMatrix();

glPopAttrib();
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

glBindTexture(GL_TEXTURE_2D, FBOTex);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glPushMatrix();
glBegin(GL_QUADS);
	glTexCoord2f(0.0, 0.0); glVertex2f(-1.0, -1.0);
	glTexCoord2f(0.0, 1.0); glVertex2f(-1.0,  1.0);
	glTexCoord2f(1.0, 1.0); glVertex2f( 1.0,  1.0);
	glTexCoord2f(1.0, 0.0); glVertex2f( 1.0, -1.0);
glEnd();
glPopMatrix();
glutSwapBuffers();

Sleep(1);


Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!