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 08-15-2010, 08:45 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: London/Peterborough
Posts: 562
QuantumDoja is on a distinguished road
Default Open GL ES render quad behind

Hi, I am rendering to texture on an FBO, I then render that texture to my screen, the problem is, no matter what I order I draw my scene in, the FBO drawn texture is rendered on top, it should be rendered at the bottom:

eg:
Background text <-rendered from FBO
Fruit images <- should render on top

but the the background always renders on top!

I think it's something to do with how I am creating the texture in the AddToTexture method, any ideas?

Setup
Code:
GLuint es1myTextureId;
GLuint es1tmpFrameBuffer;

glGenFramebuffersOES(1, &es1tmpFrameBuffer);
		glGenTextures ( 1, &es1myTextureId );		
		glBindTexture ( GL_TEXTURE_2D, es1myTextureId );
		glTexImage2D ( GL_TEXTURE_2D, 0, GL_RGBA, del.BufferWidth, del.BufferHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
		glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
		glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
		glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
		glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
Render loop
Code:
[EAGLContext setCurrentContext:context];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer);
    glViewport(0, 0, backingWidth, backingHeight);
glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
	glClearDepthf(1.0);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glOrthof(0, del.Width, 0, del.Height, -1, 1);

	
	
	
	[self AddToTexture];
	[self DrawGeneratedTexture:es1myTextureId];
	[self DrawFruit];

glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
    [context presentRenderbuffer:GL_RENDERBUFFER_OES];
Helpers:
Code:
-(void)AddToTexture
{
	
	glEnable ( GL_BLEND );
	glBlendFunc ( GL_SRC_ALPHA, GL_ONE );
	
	glBindFramebufferOES(GL_FRAMEBUFFER_OES, es1tmpFrameBuffer);
	glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, es1myTextureId, 0);
	
	if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES)
	{
		printf("CANNOT CREATE FRAMEBUFFER\n");
	}
	

	for (UITouch *touch in del.GameRef.TouchSet) {
		
		
		float s[3];
		s[0] = 100;
		s[1] = 100;
		s[2] = 100;
		
		
		
		CGPoint touchPoint = [touch locationInView:del.GameRef.ViewRef];


		int x = touchPoint.x - 16;
		int y = touchPoint.y - 16;
		
		int w = 32;
		int h = 32;
		
		
		GLfloat vertices[] = {
			x,		y, 0,
			x+w,	y, 0,
			x,		y+h, 0,
			x+w,	y+h, 0,
		};
		
		GLfloat texCoords[] = {
			0.0,	1.0,
			1.0,	1.0,
			0.0,	0.0,
			1.0,	0.0,
		};
		
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, del.textureBrush);
		glVertexPointer(3, GL_FLOAT, 0, vertices);
		glEnableClientState(GL_VERTEX_ARRAY);
		
		glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
		
		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
		glDisable(GL_TEXTURE_2D);	
	}

	glDisable ( GL_BLEND );

	glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer);	
}

Code:
-(void)DrawGeneratedTexture:(GLuint)te
{
	
	int w = del.BufferWidth;
	int h = del.BufferHeight;
	
	GLfloat vertices[] = {
		0,		0,
		w,		0,
		0,		h,
		w,		h,
	};
	
	GLfloat texCoords[] = {
		0.0,	1.0,
		1.0,	1.0,
		0.0,	0.0,
		1.0,	0.0,
	};
	
	
	
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, te);
	
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	
	glVertexPointer(2, GL_FLOAT, 0, vertices);
	glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
	
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
	
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisable(GL_TEXTURE_2D);	
	

}
QuantumDoja is offline   Reply With Quote
Reply

Bookmarks

Tags
open gl es 1.1, opengl

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: 400
11 members and 389 guests
7twenty7, ChrisYates, djohnson, Duncan C, gmarro, hussain1982, Kirkout, Retouchable, SLIC, walex, xzoonxoom
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,679
Threads: 94,128
Posts: 402,921
Top Poster: BrianSlick (7,990)
Welcome to our newest member, xzoonxoom
Powered by vBadvanced CMPS v3.1.0

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