Skip to main content
GameDev.net gamedev.net
🔒 Locked

Framebuffer object. Texture coordinate system.

Started by cyrax256 Nov 21, 2006 at 10:50 PM 5 replies 2.5k views
Original Post
cyrax256
cyrax256
Hey guys, I have some kind of confusion about the coordinate system of the texture attached to an FBO. I've created a 128x128 texture, I set up a 2d orthogonal projection from 0 to 128 in X and Y, and I'm directly rendering a triangle in the points (0, 0), (40, 40) and (0, 40). The texture dump gives me this image:
Texture Dump
Not only that a triangle of those dimensions goes out of the texture, but also the texture looks stretched horizontally! Please see the code shown next for more details:

//Creating a new texture and initializing with a triangle

glBindTexture(GL_TEXTURE_2D, fluid->velocityTexture[0]);
//Setting texture parameters
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);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

//Creation of the texture
glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, GL_RGBA, GL_FLOAT, textureCanvas);
//Attachment to FBO
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
                          GL_TEXTURE_2D, fluid->velocityTexture[0], 0);
//This assumes I'm already bound to the FBO
glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, width, 0, height); //Width and height of the texture (128x128)
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBegin(GL_TRIANGLES);
	glColor4f(0.75f, 0.75f, 0.75f, 1.0f);
	glVertex2f(0.0f, 0.0f);
	glVertex2f(40.0f, 40.0f);
	glVertex2f(0.0f, 40.0f);
glEnd();
glPopMatrix();
glFinish();

Have you rendered successfully with FBOs? Did you find any issues with the coordinates inside the texture? I'd really appreciate any light on the matter. Thank you very much, Ciro. NOTE: FYI, I've read the FBO extension registry and it does not dwell too much into screen coordinates for textures. If you spot something I've missed, I will also be very grateful :-).
HellRaiZer
HellRaiZer
Are you setting the viewport to the dimensions of the texture?

glViewport(0, 0, width, height);

AFAIK FBOs share the same context as the main OpenGL window, so all the window attributes are shared. You have to switch the viewport to the texture's dimensions before rendering the triangle, and revert back to the window's dimensions afterwards (if you want to render anything to the window).

HellRaiZer
HellRaiZer
_the_phantom_
_the_phantom_
Quote:
Original post by HellRaiZer
AFAIK FBOs share the same context as the main OpenGL window, so all the window attributes are shared. You have to switch the viewport to the texture's dimensions before rendering the triangle, and revert back to the window's dimensions afterwards (if you want to render anything to the window).


Indeed, this is correct *waves at the FBO101 article on the front page written by some really great guy*



[grin]

HellRaiZer
HellRaiZer
Quote:
Original post by phantom
Quote:
Original post by HellRaiZer
AFAIK FBOs share the same context as the main OpenGL window, so all the window attributes are shared. You have to switch the viewport to the texture's dimensions before rendering the triangle, and revert back to the window's dimensions afterwards (if you want to render anything to the window).


Indeed, this is correct *waves at the FBO101 article on the front page written by some really great guy*
[grin]

Nice article. I don't visit the front page often so i think i missed it :)
One little (and useless) comment. The link to the printer friendly version is broken :) Not that i want to print it but i find it easier to read something when it is continuous, and i don't have to click to a link every 5 seconds.

HellRaiZer
HellRaiZer
PlayerX
PlayerX
Quote:
Original post by phantom
Indeed, this is correct *waves at the FBO101 article on the front page written by some really great guy*
[grin]


That's a nice article btw. I've been meaning to look into FBOs and that was some nice coverage.

One thing that bothers me is why only newer video cards appear to support them? Direct3D has been supporting decent render-to-texture for years and from what I understand most cards from the last five or six years can do it. It'd be nice to get rid of my old Pbuffer code completely (god what a stupid, stupid idea Pbuffers were), but I need to support older cards, and unless FBOs will be added to these older cards, I won't be able to. :(

Anybody know why this is? Does an FBO do something the Direct3D RTT mechanism doesn't?
_the_phantom_
_the_phantom_
you'd have to ask the driver writers, although I suspect it's pretty much a case of abandoning old hardware as time moves on.
cyrax256
cyrax256
Thank you very mucho, HellRaiZer, this was happening indeed, and now the textures look correctly. :-)

And thanks a lot, phantom, I wish I had found that tutorial before :-), as I have been learning this with some nVidia PDFs and the extension registry itself (the hard way, let's call it :0) ). I will direct people to your tutorial if I find questions related.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.