You Like My Tutorials? Click The Banner To Keep 'Em Coming!

glGameDeveloper(): The Game Developer's Source for OpenGL Coding
Main Menu
Latest News
Archived News
Tutorials
Links
E-Mail Me

Other
Message Board
My Guestbook

Tutorials -- glFeedbackBuffer
 


Using glFeedbackBuffer Page 2 of 3
< Previous Jump to Page: 1 | 2 | 3 Next >

The Source Code

Ok, lets get to it. First we have to make a variable through which OpenGL returns our information.

GLfloat buf[4];

Second step is to tell OpenGL how we want to use the FeedbackBuffer. We have to do this before we set our RenderMode to FeedbackBuffer, otherwise we get an error. Use this line of code to do it:

glFeedbackBuffer(4, GL_3D, (float *)buf);

What do these parameters do?

  • The "4" tells OGL how many values to return. While we only want x, y, and z coordinates, FeedbackBuffer needs one other value for some reason. Wierd, yes, but all I know is this extra value doesn't matter.
  • "GL_3D" means that we want to get the 3d coordinates of what will be rendered. Note that instead of returning an actual Z coordinate value, it returns a floating point decimal between 0 and 1, 0 meaning close to the viewer and 1 meaning far away from the viewer.
  • "(float *)buf" gives OpenGL the pointer to our return buffer.

Now lets turn on Feedback:

glRenderMode(GL_FEEDBACK);

Now we can do stuff to get feedback. A good way to do this is to simply render a point at the spot we want to test.

glBegin(GL_POINTS);
	glVertex3f(x, y, z);
glEnd();

Finally, lets turn off Feedback and set our RenderMode back to GL_RENDER:

glRenderMode(GL_RENDER);

Move on to see how to use this feedback.

Using glFeedbackBuffer Page 2 of 3
< Previous Jump to Page: 1 | 2 | 3 Next >

This site best viewed with MS Internet Explorer 5.0 at 16-bit color and at least 800x600.

All Contents of this site are Copyright 1999, 2000 Joe Zimmerman. No part of this site (code, HTML, etc.) may be reproduced without my permission.

Click Here!