View Full Version : feedback buffer problem
kelvin
2003.03.29, 06:05 AM
I'm using the feedback buffer to get tex coords from screen coords. It works fine except for the very first poly I draw in immediate mode. The tex coords I get back are mirrored across the seam where the two triangles meet in the middle of the quad. This only happens on the very first rect I draw in immediate mode in feedback rendermode. This doesn't happen with the polys I draw from coordarrays. I'm not sure what is happening because the problem doesn't occur after the first poly. I'm setting the render mode back to render, and then back to feedback between each set of polys so I can better keep track of the texture I'm working with and to keep my buffer small.
Does anyone know what's going on or how to fix?
[edit: I fixed it]
MacFiend
2003.03.29, 07:08 AM
Do you call glFeedbackBuffer before you set the render mode to feedback? Not sure if it's relevant, but it's the most I can come up with without any code to look at.
kelvin
2003.03.29, 09:08 PM
yes, I call glFeedbackBuffer before I set the rendermode.
[edit] here's my code:
int bufferSize = 1024;
GLfloat feedBuffer[bufferSize];
glFeedbackBuffer (bufferSize, GL_3D_COLOR_TEXTURE, feedBuffer);
while ( sprite = [sprts nextObject] ) {
if ( [sprite visible] ) {
(void) glRenderMode (GL_FEEDBACK);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, NULL);
glBegin (GL_TRIANGLE_STRIP); {
glVertex3d (width, 0, 0.0); glTexCoord2f (1.0, 1.0);
glVertex3d (width, height, 0.0); glTexCoord2f (0.0, 0.0);
glVertex3d (0, 0, 0.0); glTexCoord2f (0.0, 1.0);
glVertex3d (0, height, 0.0); glTexCoord2f (1.0, 0.0);
} glEnd();
GLint size = glRenderMode (GL_RENDER);
GLfloat token;
GLint count = size;
while (count) {
token = feedBuffer[size-count]; count--;
if (token == GL_POLYGON_TOKEN) {
int polycount = feedBuffer[size-count]; count--;
from here I just get feedBuffer[size-count+7] and feedBuffer[size-count+8] to get the coordinates relative to the quad. As I said, this only messes up with the first immediate mode sprite I draw.
to see the weirdness in action, I've provided a build:
http://www.variableaspect.com/experiments/CocoaBlitz/weirdfeedback.sit
one of the big browse hands gets correct coords (the second one) while the first one gets the weird mirroring. I have the exact coords move around the screen in a text sprite (drawarrays doesn't seem to be affected) so you can see the weirdness.
kelvin
2003.03.30, 11:20 AM
ok, just to show off my complete opengl newbness, my problem came from calling my vertexcoords BEFORE my texturecoords. I totally didn't know you couldn't do this.
um, also I noticed that for whatever reason, I'm trying to stick floats into int params; this wasn't causing problems, just bad programming.
anyhow, I changed my draw code to this:
glBegin (GL_TRIANGLE_STRIP); {
glTexCoord2d (1, 0); glVertex3d (width, 0, 0);
glTexCoord2d (1, 1); glVertex3d (width, height, 0);
glTexCoord2d (0, 0); glVertex3d (0, 0, 0);
glTexCoord2d (0, 1); glVertex3d (0, height, 0);
} glEnd();
and now everything seems to be working ok. (crosses fingers and toes):shock:
Arent you supposed to push a name (0) onto the selection name stack in the beginning, before anything is drawn in selection mode?
OneSadCookie
2003.04.02, 07:46 AM
Why? Only the top name in the stack is used for anything... The usual usage is simply to call glLoadName for each object, with a different id each time.
Mark Levin
2003.04.02, 12:50 PM
You are supposed to do one push to "prime" the stack before you can start using it in selection mode, according to the red book.
kelvin
2003.04.02, 03:07 PM
Feedbackbuffer != SelectionBuffer.
feedback (http://www.opengl.org/developers/documentation/man_pages/hardcopy/GL/html/gl/feedbackbuffer.html)
select (http://www.opengl.org/developers/documentation/man_pages/hardcopy/GL/html/gl/selectbuffer.html)
Originally posted by kelvin
Feedbackbuffer != SelectionBuffer.
feedback (http://www.opengl.org/developers/documentation/man_pages/hardcopy/GL/html/gl/feedbackbuffer.html)
select (http://www.opengl.org/developers/documentation/man_pages/hardcopy/GL/html/gl/selectbuffer.html)
sorry, wasn't thinking.
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.