613 616














Open GL Super Bible:Interactive Graphics















To access the contents, click the chapter and section titles.


Open GL Super Bible


(Publisher: Macmillan Computer Publishing)

Author(s): Waite group Press

ISBN: 1571690735

Publication Date: 08/01/96



function isIE4()
{
return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)==
'4')
); }
function
bookMarkit() {varurl="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0";
parent.location.href=url;
//var win = window.open(url,"myitk");
//if(!isIE4())
// win.focus();

}

 




Previous
Table of Contents
Next




glRenderMode

Purpose
Sets one of three rasterization modes.
Include File
<gl.h>
Syntax
GLint glRenderMode(GLenum mode);
Description
OpenGL operates in three modes when you call your drawing functions:
GL_RENDER: Render mode (the default). Drawing functions result in pixels in the framebuffer.
GL_SELECT: Selection mode. No changes to the
framebuffer are made. Rather, hit records are written to the selection
buffer that record primitives that would have been drawn within the
viewing volume. The selection buffer must be allocated and specified
first with a call to glSelectBuffer. GL_FEEDBACK: Feedback mode. No
changes to the framebuffer are made. Instead coordinates and attributes
of vertices that would have been rendered in render mode are written to
a feedback buffer. The feedback buffer must be allocated and specified
first with a call to glFeedbackBuffer.


Parameters

mode

GLenum: Specifies the rasterization mode. May be any one of GL_RENDER, GL_SELECT, and GL_FEEDBACK. The default value is GL_RENDER.
Returns
The return value depends on the rasterization mode that was set the last time this function was called:
GL_RENDER: Zero.
GL_SELECT: The number of hit records written to the selection buffer.
GL_FEEDBACK: The number of values written to the
feedback buffer. Note, this is not the same as the number of vertices
written.


Example
The following code shows glRenderMode being called to enter selection mode for the PLANETS example program. The function is called again with an argument of GL_RENDER to enter rendering mode and to write the hit records into the selection buffer.

// Process the selection, which is triggered by a right mouse
// click at (xPos, yPos).
#define BUFFER_LENGTH 64
void ProcessSelection(int xPos, int yPos)
{
// Space for selection buffer
GLuint selectBuff[BUFFER_LENGTH];

// Hit counter and viewport storage
GLint hits, viewport[4];

// Set up selection buffer
glSelectBuffer(BUFFER_LENGTH, selectBuff);

// Get the viewport
glGetIntegerv(GL_VIEWPORT, viewport);

// Switch to projection and save the matrix
glMatrixMode(GL_PROJECTION);
glPushMatrix();

// Change render mode
glRenderMode(GL_SELECT);

// Establish new clipping volume to be unit cube around
// mouse cursor point (xPos, yPos) and extending two pixels
// in the vertical and horizontal direction
glLoadIdentity();
gluPickMatrix(xPos, yPos, 2,2, viewport);

// Apply perspective matrix
gluPerspective(45.0f, fAspect, 1.0, 425.0);

// Draw the scene
RenderScene();

// Collect the hits
hits = glRenderMode(GL_RENDER);

// If a single hit occurred, display the info.
if(hits == 1)
ProcessPlanet(selectBuff[3]);

// Restore the projection matrix
glMatrixMode(GL_PROJECTION);
glPopMatrix();

// Go back to modelview for normal rendering
glMatrixMode(GL_MODELVIEW);
}


See Also
glFeedbackBuffer, glInitNames, glLoadName,
glPassThrough, glPushName, glSelectBuffer


glSelectBuffer

Purpose
Sets the buffer to be used for selection values.
Include File
<gl.h>
Syntax
void glSelectBuffer(GLsizei size, GLuint *buffer);
Description
When OpenGL is in selection mode (GL_SELECT),
drawing commands do not produce pixels in the framebuffer. Instead they
produce hit records that are written to the selection buffer that is
established by this function. Each hit record consists of the following
data:



1.  The number of names on the names stack when the hit occurred.
2.  The minimum and maximum z values of all the vertices of the primitives that intersected the viewing volume. This value is scaled to range from 0.0 to 1.0.
3.  The
contents of the name stack at the time of the hit, starting with the
bottommost element.

Parameters

size

GLsize: The number of values that can be written into the buffer established by *buffer.
buffer

GLuint*: A pointer to memory that will contain the selection hit records.
Returns
None.


Example
The following code shows the selection buffer being created for the PLANETS example program.

// Process the selection, which is triggered by a right mouse
// click at (xPos, yPos).
#define BUFFER_LENGTH 64
void ProcessSelection(int xPos, int yPos)
{
// Space for selection buffer
GLuint selectBuff[BUFFER_LENGTH];

...
...

// Set up selection buffer
glSelectBuffer(BUFFER_LENGTH, selectBuff);


See Also
glFeedbackBuffer, glInitNames, glLoadName,
glPushName, glRenderMode






Previous
Table of Contents
Next














 


Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.












Wyszukiwarka