/////////////////////////////////////////////////////////// // Render the torus and sphere void DrawObjects(void) { // Save the matrix state and do the rotations glMatrixMode(GL_MODELVIEW); glPushMatrix(); // Translate the whole scene out and into view glTranslatef(-0.75f, 0.0f, -2.5f); // Initialize the names stack glInitNames(); glPushName(0); // Set material color, Yellow // torus glColor3f(1.0f, 1.0f, 0.0f); glLoadName(TORUS); glPassThrough((GLfloat)TORUS); DrawTorus(40, 20); // Draw Sphere glColor3f(0.5f, 0.0f, 0.0f); glTranslatef(1.5f, 0.0f, 0.0f); glLoadName(SPHERE); glPassThrough((GLfloat)SPHERE); DrawSphere(0.5f); // Restore the matrix state glPopMatrix(); // Modelview matrix }
/////////////////////////////////////////////////////////// // Render the torus and sphere void DrawObjects(void) { glMatrixMode(GL_MODELVIEW); glPushMatrix(); glTranslatef(-0.75f, 0.0f, -2.5f); //初始化名称栈 glInitNames(); glPushName(0); //圆环 glColor3f(1.0f, 1.0f, 0.0f); //圆环的名称 glLoadName(TORUS); //设置一个自定义的过渡标记,与圆环的名称相同,以便后面的解析判断 glPassThrough((GLfloat)TORUS); DrawTorus(40, 20); //球体 glColor3f(0.5f, 0.0f, 0.0f); glTranslatef(1.5f, 0.0f, 0.0f); //球体的名称 glLoadName(SPHERE); //球体的过渡标记 glPassThrough((GLfloat)SPHERE); DrawSphere(0.5f); glPopMatrix(); }
// Render the cube and sphere void DrawObjects(void) { // Save the matrix state and do the rotations glMatrixMode(GL_MODELVIEW); glPushMatrix(); // Translate the whole scene out and into view glTranslatef(-80.0f, 0.0f, -300.0f); // Initialize the names stack glInitNames(); glPushName(0); // Set material color, Yellow // Cube glRGB(255, 255, 0); glLoadName(CUBE); glPassThrough((GLfloat)CUBE); glutSolidCube(75.0f); // Draw Sphere glRGB(128,0,0); glTranslatef(130.0f, 0.0f, 0.0f); glLoadName(SPHERE); glPassThrough((GLfloat)SPHERE); glutSolidSphere(50.0f, 15, 15); // Restore the matrix state glPopMatrix(); // Modelview matrix }
void CPhysEnv::GetNearestPoint(int x, int y) { /// Local Variables /////////////////////////////////////////////////////////// float *feedBuffer; int hitCount; tParticle *tempParticle; int loop; /////////////////////////////////////////////////////////////////////////////// // INITIALIZE A PLACE TO PUT ALL THE FEEDBACK INFO (3 DATA, 1 TAG, 2 TOKENS) feedBuffer = (float *)malloc(sizeof(GLfloat) * m_ParticleCnt * 6); // TELL OPENGL ABOUT THE BUFFER glFeedbackBuffer(m_ParticleCnt * 6,GL_3D,feedBuffer); (void)glRenderMode(GL_FEEDBACK); // SET IT IN FEEDBACK MODE tempParticle = m_CurrentSys; for (loop = 0; loop < m_ParticleCnt; loop++) { // PASS THROUGH A MARKET LETTING ME KNOW WHAT VERTEX IT WAS glPassThrough((float)loop); // SEND THE VERTEX glBegin(GL_POINTS); glVertex3fv((float *)&tempParticle->pos); glEnd(); tempParticle++; } hitCount = glRenderMode(GL_RENDER); // HOW MANY HITS DID I GET //fout<<"hit count "<<hitCount<,endl; CompareBuffer(hitCount,feedBuffer,(float)x,(float)y); // CHECK THE HIT free(feedBuffer); // GET RID OF THE MEMORY }
/* Draw a few lines and two points, one of which will * be clipped. If in feedback mode, a passthrough token * is issued between the each primitive. */ void drawGeometryFeedback(GLenum mode) { glBegin(GL_LINE_STRIP); glNormal3f(0.0, 0.0, 1.0); glVertex3f(30.0, 30.0, 0.0); glVertex3f(50.0, 60.0, 0.0); glVertex3f(70.0, 40.0, 0.0); glEnd(); if (mode == GL_FEEDBACK) glPassThrough(1.0); glBegin(GL_POINTS); glVertex3f(-100.0, -100.0, -100.0); /* will be clipped */ glEnd(); if (mode == GL_FEEDBACK) glPassThrough(2.0); glBegin(GL_POINTS); glNormal3f(0.0, 0.0, 1.0); glVertex3f(50.0, 50.0, 0.0); glEnd(); }
void DrawObjects(void) { glMatrixMode(GL_MODELVIEW); glPushMatrix(); if (gridFlag == 1){drawGrid();} glTranslatef(0.0f, 0.0f, -120.5f); glInitNames(); glPushName(0); if (scene.size() != 0) { for (int i = 0; i < scene.size(); ++i) { glColor3f((GLfloat)(rand() % 1000) * 0.001,(GLfloat)(rand() % 1000) * 0.001,(GLfloat)(rand() % 1000) * 0.001); printf("%f\n", (GLfloat)(rand() % 1000) * 0.001); glLoadName(i + 1); glPassThrough((GLfloat)i + 1); glPushMatrix(); scene[i]->paintMyself(); glPopMatrix(); } } glMatrixMode(GL_MODELVIEW); glPopMatrix(); }
void GlNode::draw(float lod,GlGraphInputData* data,Camera*) { const Color& colorSelect2=data->parameters->getSelectionColor(); glEnable(GL_CULL_FACE); node n=node(id); if (data->getElementSelected()->getNodeValue(n)) { glDisable(GL_DEPTH_TEST); if(data->getGraph()->isMetaNode(n)) { glStencilFunc(GL_LEQUAL,data->parameters->getSelectedMetaNodesStencil(),0xFFFF); } else { glStencilFunc(GL_LEQUAL,data->parameters->getSelectedNodesStencil(),0xFFFF); } } else { glEnable(GL_DEPTH_TEST); if(data->getGraph()->isMetaNode(n)) { glStencilFunc(GL_LEQUAL,data->parameters->getMetaNodesStencil(),0xFFFF); } else { glStencilFunc(GL_LEQUAL,data->parameters->getNodesStencil(),0xFFFF); } } const Coord &nodeCoord = data->getElementLayout()->getNodeValue(n); const Size &nodeSize = data->getElementSize()->getNodeValue(n); const Color& fillColor = data->getElementColor()->getNodeValue(n); const Color& strokeColor = data->getElementBorderColor()->getNodeValue(n); const Color& textColor = data->getElementLabelColor()->getNodeValue(n); GlTextureManager::getInst().setAnimationFrame(data->getElementAnimationFrame()->getNodeValue(n)); if(data->parameters->getFeedbackRender()) { glPassThrough(TLP_FB_COLOR_INFO); glPassThrough(fillColor[0]); glPassThrough(fillColor[1]); glPassThrough(fillColor[2]); glPassThrough(fillColor[3]); glPassThrough(strokeColor[0]); glPassThrough(strokeColor[1]); glPassThrough(strokeColor[2]); glPassThrough(strokeColor[3]); glPassThrough(textColor[0]); glPassThrough(textColor[1]); glPassThrough(textColor[2]); glPassThrough(textColor[3]); glPassThrough(TLP_FB_BEGIN_NODE); glPassThrough(static_cast<float>(id)); //id of the node for the feed back mode } bool selected = data->getElementSelected()->getNodeValue(n); if (lod < data->parameters->getPointModeLOD()) { //less than four pixel on screen, we use points instead of glyphs if (lod < 1) lod = 1; int size= static_cast<int>(sqrt(lod)); if(data->getGlVertexArrayManager()->renderingIsBegin()) { if(size<2) data->getGlVertexArrayManager()->activatePointNodeDisplay(this,true,selected); else data->getGlVertexArrayManager()->activatePointNodeDisplay(this,false,selected); } else { if(size>2) size=2; const Color& color = selected ? colorSelect2 : fillColor; OpenGlConfigManager::getInst().activateLineAndPointAntiAliasing(); glDisable(GL_LIGHTING); setColor(color); glPointSize(static_cast<float>(size)); glBegin(GL_POINTS); glVertex3f(nodeCoord[0], nodeCoord[1], nodeCoord[2]+nodeSize[2]/2.f); glEnd(); glEnable(GL_LIGHTING); OpenGlConfigManager::getInst().desactivateLineAndPointAntiAliasing(); } return; } //draw a glyph or make recursive call for meta nodes glPushMatrix(); glTranslatef(nodeCoord[0], nodeCoord[1], nodeCoord[2]); glRotatef(static_cast<float>(data->getElementRotation()->getNodeValue(n)), 0.f, 0.f, 1.f); // If node size in z is equal to 0 we have to scale with FLT_EPSILON to preserve normal // (because if we do a scale of (x,y,0) and if we have a normal like (0,0,1) the new normal after scale will be (0,0,0) and we will have light problem) if(nodeSize[2]==0) glScalef(nodeSize[0], nodeSize[1],FLT_EPSILON); else glScalef(nodeSize[0], nodeSize[1],nodeSize[2]); data->glyphs.get(data->getElementShape()->getNodeValue(n))->draw(n,lod); if (selected) { OpenGlConfigManager::getInst().activateLineAndPointAntiAliasing(); selectionBox->setStencil(data->parameters->getSelectedNodesStencil()-1); selectionBox->setOutlineColor(colorSelect2); selectionBox->draw(10,NULL); OpenGlConfigManager::getInst().desactivateLineAndPointAntiAliasing(); } glPopMatrix(); if (selected) { glStencilFunc(GL_LEQUAL,data->parameters->getNodesStencil(),0xFFFF); } GlTextureManager::getInst().setAnimationFrame(0); if(data->parameters->getFeedbackRender()) { glPassThrough(TLP_FB_END_NODE); } }
M(void, glPassThrough, jfloat token) { glPassThrough(token); }
///////////////////////////////////////////////////////// // Render // void GEMglPassThrough :: render(GemState *state) { glPassThrough (token); }
void __glXDisp_PassThrough(GLbyte *pc) { glPassThrough( *(GLfloat *)(pc + 0) ); }
/* draw a model in feedback mode and return the list of visible vertices */ void DrawModelFeedbackMode( Model *model, int width, int height, Viewer3dParam *par, vector<int> &vertexIndices ) { glEnable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glRenderMode (GL_RENDER); GlClearWindow(1); Setup3d( par ); DrawModel( model, 0); GLfloat *pixels = (GLfloat*)malloc(3*width*height*sizeof(GLfloat)); glReadPixels(0,0,width, height, GL_DEPTH_COMPONENT,GL_FLOAT,(void*)pixels); // no texture int ii; // init feedback mode int BUFSIZE_FEEDBACK = 6 * ( model->NVertices() + 1 ); GLfloat *feedbackBuffer = (GLfloat *)malloc(BUFSIZE_FEEDBACK*sizeof(GLfloat)); if ( feedbackBuffer == NULL ) { dbg(DBG_INFO, "Failed to init feedback data!\n"); } glFeedbackBuffer(BUFSIZE_FEEDBACK,GL_3D,feedbackBuffer); // set mode to feedback glRenderMode(GL_FEEDBACK); Setup3d( par ); for (ii=0;ii<model->NVertices();ii++) { Vec3f vx = model->GetVertex(ii).v(); // pass index in feedback mode glPassThrough(ii); glBegin(GL_POINTS); glVertex3f( vx[0], vx[1], vx[2] ); glEnd(); } // retrieve feedback GLuint hits = glRenderMode( GL_RENDER ); // parse hits if ( (int)hits != -1 ) { GLfloat *ptr = (GLfloat*)feedbackBuffer; GLfloat x,y,z; GLint code,id; int counter =0; for (ii=0;ii<(int)hits;ii++) { code = (int)*ptr; if ( code == GL_PASS_THROUGH_TOKEN ) { id = (int)*(ptr+1); ptr+=2; ii+=1; continue; } if ( code == GL_POINT_TOKEN ) { x = *(ptr+1); y = *(ptr+2); z = *(ptr+3); int xx = x - floor(x) > 0.5 ? int(floor(x))+1 : int(floor(x)); int yy = y - floor(y) > 0.5 ? int(floor(y))+1 : int(floor(y)); if ( xx < width - 1 && xx > 1 && \ yy < height - 1 && yy > 1 ) { float thresh = MAX( MAX( MAX( pixels[yy*width+xx], pixels[(yy-1)*width+xx]), pixels[yy*width+xx-1] ), pixels[(yy-1)*width+xx-1] ); if ( z <= thresh + 1E-5 ) { vertexIndices.push_back( id ); counter++; } } ptr += 4; ii += 3; continue; } } dbg(DBG_INFO,"%d visible points (%d model points)\n", counter, model->NVertices()); } // free memory delete ( feedbackBuffer ); delete ( pixels ); }