Attention: iDevGames forum has a new home at http://www.idevgames.com/forums.
Please update your bookmarks and linkage.
This forum has been locked and will be available for archival purposes only.
iDevGames - Mac, iPhone, iPad & iPod Game Developers Forum  


iPhone, iPad & iPod Game Development Game programming topics devoted to the Apple iPhone, iPad & iPod.

 
 
Thread Tools Display Modes
Old
  (#1)
auptown
Member
 
Posts: 4
Join Date: 2009.04
Location: Boulder, CO
openGL n00b looking for FBO drawing examples or direction - 2009.04.24, 11:49 AM

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!
   
Old
  (#2)
arekkusu
Member
 
Posts: 1,334
Join Date: 2002.10
Location: Sunnyvale, CA
2009.04.24, 01:40 PM

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.
   
Old
  (#3)
auptown
Member
 
Posts: 4
Join Date: 2009.04
Location: Boulder, CO
2009.04.24, 02:04 PM

Quote:
Originally Posted by arekkusu View Post
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
   
Old
  (#4)
auptown
Member
 
Posts: 4
Join Date: 2009.04
Location: Boulder, CO
2009.04.25, 12:55 PM

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!!!!!!
   
Old
  (#5)
lookitsash
Nibbie
 
Posts: 2
Join Date: 2009.10
Location: Philadelphia, PA
2009.10.29, 11:44 AM

did you ever find a solution to your issue with the white texture?
   
Old
  (#6)
Eskema
Member
 
Posts: 14
Join Date: 2009.06
Location: Spain
2009.11.04, 04:16 AM

Quote:
Originally Posted by auptown View Post


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
   
 


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump



Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com
DevServe Network: iDevApps | uDevGames | iDevGames