Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-30-2009, 09:29 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 2
lookitsash is on a distinguished road
Default rendering framebuffer texture not working

I have read numerous articles/tutorials online regarding drawing a texture to a framebuffer in opengl, but I am having no luck getting it to work. I am creating a framebuffer, drawing a texture to the fbo, and then drawing the fbo texture to the screen but nothing displays (just a black screen). I am at a loss. If i comment out the fbo code and draw the embedded texture directly to the screen, that works. Is there some iphone specific logic that i am missing (independent of opengl)? Here is my code:


Code:
// INITIALIZATION
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);
	glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
	
	// Load Test Texture
	glGenTextures(1, &textureTest);
	glBindTexture(GL_TEXTURE_2D, textureTest);			// Bind Our Texture
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);	// Linear Filtered
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	// Linear Filtered
	[self loadTexture: @"texture"]; // calls glTexImage2D with image data from png
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glViewport(0,0, 320.0f,480.0f);
	glOrthof(0,320.0f, 480.0f,0, -1.0f, 1.0f); // left, right, bottom, top
	glMatrixMode(GL_MODELVIEW);
	
	//FBO Setup
	glGenTextures(1, &textureFBO); // texture handle
	glBindTexture(GL_TEXTURE_2D, textureFBO); //bind it.
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); 
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);	// Linear Filtered
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	// Linear Filtered
	
	glGenFramebuffersOES(1, &FBO); // frame buffer 
	glBindFramebufferOES(GL_FRAMEBUFFER_OES, FBO); //bind the frame buffer
	
	// attach texture to framebuffer color buffer
	glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, textureFBO, 0);
	if(glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES)  printf("CANNOT CREATE FRAMEBUFFER\n");
 
 
// MAIN DRAWING LOOP
	static const Vertex3D vertices[] = {
        	{ 0.0,  100.0, 0.0},
        	{ 100.0,  100.0, 0.0},
        	{ 0.0, 200.0, 0.0},
        	{ 100.0, 200.0, 0.0}
    	};
	static const GLfloat texCoords[] = {
       		0.0, 1.0,
        	1.0, 1.0,
        	0.0, 0.0,
        	1.0, 0.0
    	};
	
	glClear(GL_COLOR_BUFFER_BIT);
	glLoadIdentity();
	
	// Render to texture
	glBindFramebufferOES(GL_FRAMEBUFFER_OES, FBO);
	
	// Draw test texture
	glBindTexture(GL_TEXTURE_2D, textureTest);
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    	glVertexPointer(3, GL_FLOAT, 0, vertices);
	glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
    	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	glBindTexture(GL_TEXTURE_2D, 0); //disable any bound textures.
	// End draw test texture
	
	// Render to screen
	glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); 
	
	// Draw FBO texture
	glBindTexture(GL_TEXTURE_2D, textureFBO);
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    	glVertexPointer(3, GL_FLOAT, 0, vertices);
	glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	glBindTexture(GL_TEXTURE_2D, 0); //disable any bound textures.
	// End draw FBO texture
lookitsash is offline   Reply With Quote
Old 11-04-2009, 03:54 PM   #2 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 190
jeonghyunhan is on a distinguished road
Default

I did experiment with RTT (render to texture) involving using FBOs so this may be useful:
Code:
// Setup FBO
glGenFramebuffersOES(1, &FBO);;
		glBindFramebufferOES(GL_FRAMEBUFFER_OES, FBO);
		glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, textures[3], 0);
		GLuint status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES);
		if (status != GL_FRAMEBUFFER_COMPLETE_OES) {
			NSLog(@"Failed to generate frame buffer");
		}
		glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);

// Loop
glBindFramebufferOES(GL_FRAMEBUFFER_OES, FBO);
	glViewport(0, 0, 320, 480);
	
// Draw code
	glColorMask(0, 0, 0, 1);
	glBlendFunc(GL_ZERO, GL_SRC_ALPHA);
	glBindTexture(GL_TEXTURE_2D, textures[0]);
	[level renderHoles:q :A];
	glColorMask(1, 1, 1, 1);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	
	glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
__________________
Blockle:http://www.youtube.com/watch?v=vxEKDkpAfRU
jeonghyunhan is offline   Reply With Quote
Old 11-04-2009, 04:13 PM   #3 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 2
lookitsash is on a distinguished road
Default

I was able to resolve the issue. I never re-binded the framebuffer that draws directly to the screen:

glBindFramebufferOES(GL_FRAMEBUFFER_OES, 1);
lookitsash is offline   Reply With Quote
Reply

Bookmarks

Tags
fbo, framebuffer, opengl, texture

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 398
7 members and 391 guests
13dario13, ChrisYates, fredidf, iOS.Lover, Leslie80, Wikiboo, Yosh_K
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,670
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Yosh_K
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:40 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0