ofVec3f ofkMatrixHelper::getUnProjectionPoint(float ofScreenPosX, float ofScreenPosY, const GLdouble *model, const GLdouble *proj, const GLint *viewPort) { ofVec3f res; // ---------------- SETTING MATRIX ---------------- // glViewport(viewPort[0], viewPort[1], viewPort[2], viewPort[3]); glMatrixMode(GL_PROJECTION); glPushMatrix(); #ifdef _WIN32 glLoadMatrixd(proj); #else { float mat[16]; for(int i = 0 ;i < 16; i++) { mat[i] = proj[i]; } glLoadMatrixf(mat); } #endif glMatrixMode(GL_MODELVIEW); glPushMatrix(); #ifdef _WIN32 glLoadMatrixd(model); #else { float mat[16]; for(int i = 0 ;i < 16; i++) { mat[i] = model[i]; } glLoadMatrixf(mat); } #endif // ---------------- DRAW and pickup points --------------- // //Enable Depth glEnable(GL_DEPTH_TEST); //DEpth Buffer Clear glClear(GL_DEPTH_BUFFER_BIT); //Once Render one Plane to Draw Depth Buffer ofEnableAlphaBlending(); ofSetColor(255, 255, 255, 0); ofFill(); ofRect(-10000, -10000, 20000, 20000); double objX; double objY; double objZ; float z; //#if defined WIN32 || defined TARGET_OS_MAC #if defined WIN32 glReadPixels(ofScreenPosX, viewPort[3] - ofScreenPosY ,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&z); gluUnProject(ofScreenPosX, viewPort[3] - ofScreenPosY ,z, model, proj, viewPort,&objX,&objY,&objZ); #elif defined TARGET_OS_X glReadPixels(ofScreenPosX, viewPort[3] - ofScreenPosY ,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&z); gluUnProject(ofScreenPosX, viewPort[3] - ofScreenPosY ,z,model, proj, viewPort,&objX,&objY,&objZ); #elif TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR cout << "gluUnProject and GL_DEPTH_COMPONENT is not implemented in iOS openGLES 1.0" << endl; z = 0.0; #endif res.x = objX; res.y = objY; res.z = 0.0; //no no we need to modify this glClear(GL_DEPTH_BUFFER_BIT); glDisable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); return res; }
void LEDCube::draw() { if (colors == nullptr) { return; } glMatrixMode(GL_MODELVIEW); // make sure we're in Modelview mode // draw a sphere after translation // make sure to get back to the former matrix when finish drawing glPushMatrix(); Matrix4 glMatrix = model2world; glMatrix.transpose(); glLoadMatrixd(glMatrix.getPointer()); glPointSize(pointSize); glColor3d(1, 1, 1); // white frame // draw while frame glBegin(GL_LINE_STRIP); glVertex3d(-cubeLength/2 - 5, -cubeWidth/2 - 5, -cubeDepth/2 - 5); glVertex3d(-cubeLength/2 - 5, cubeWidth/2 + 5, -cubeDepth/2 - 5); glVertex3d(cubeLength/2 + 5, cubeWidth/2 + 5, -cubeDepth/2 - 5); glVertex3d(cubeLength/2 + 5, -cubeWidth/2 - 5, -cubeDepth/2 - 5); glVertex3d(-cubeLength/2 - 5, -cubeWidth/2 - 5, -cubeDepth/2 - 5); glVertex3d(-cubeLength/2 - 5, -cubeWidth/2 - 5, cubeDepth/2 + 5); glVertex3d(cubeLength/2 + 5, -cubeWidth/2 - 5, cubeDepth/2 + 5); glVertex3d(cubeLength/2 + 5, cubeWidth/2 + 5, cubeDepth/2 + 5); glVertex3d(-cubeLength/2 - 5, cubeWidth/2 + 5, cubeDepth/2 + 5); glVertex3d(-cubeLength/2 - 5, -cubeWidth/2 - 5, cubeDepth/2 + 5); glEnd(); glBegin(GL_LINES); glVertex3d(-cubeLength/2 - 5, cubeWidth/2 + 5, cubeDepth/2 + 5); glVertex3d(-cubeLength/2 - 5, cubeWidth/2 + 5, -cubeDepth/2 - 5); glVertex3d(cubeLength/2 + 5, cubeWidth/2 + 5, cubeDepth/2 + 5); glVertex3d(cubeLength/2 + 5, cubeWidth/2 + 5, -cubeDepth/2 - 5); glVertex3d(cubeLength/2 + 5, -cubeWidth/2 - 5, cubeDepth/2 + 5); glVertex3d(cubeLength/2 + 5, -cubeWidth/2 - 5, -cubeDepth/2 - 5); glEnd(); // draw spheres glBegin(GL_POINTS); unsigned int color; unsigned int R, G, B, W; for (int z = 0; z < LED_DEPTH; ++z) { for (int x = 0; x < LED_LENGTH; ++x) { for (int y = 0; y < LED_WIDTH; ++y) { color = colors[z * LED_WIDTH * LED_LENGTH + x * LED_WIDTH + y]; if (color == 0) { continue; } W = color & 0xFF; color >>= 8; B = color & 0xFF; color >>= 8; G = color & 0xFF; color >>= 8; R = color & 0xFF; glColor4d(1.0 * (R+W) / 0X100, 1.0 * (G+W) / 0x100, 1.0 * (B+W) / 0x100, LED_ALPHA); glVertex3d(-cubeLength/2 + LED_LEN_INTERVAL * x, -cubeWidth/2 + LED_WID_INTERVAL * y, -cubeDepth/2 + LED_DEP_INTERVAL * z); } } } glEnd(); glPopMatrix(); }
//------------------------------------------------------------------------------ /// Registered OpenGL Display Callback Function void display(void) { // recompute the camera projection in case it was moved camera.project(); glMatrixMode( GL_PROJECTION ); glLoadIdentity( ); glLoadMatrixd( camera.projection.arrayOpenGL() ); // now process the scene glMatrixMode( GL_MODELVIEW ); glLoadIdentity( ); glClear (GL_COLOR_BUFFER_BIT); glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); GLfloat LightAmbient[] = { 0.4f, 0.4f, 0.4f, 1.0f}; GLfloat LightDiffuse[] = { 0.3f, 0.3f, 0.3f, 1.0f}; GLfloat LightSpecular[] = { 0.4f, 0.4f, 0.4f, 1.0f}; //GLfloat LightSpecular[] = { 0.0f, 0.0f, 0.0f, 1.0f}; //GLfloat LightPosition[] = { 5.0f, 5.0f, 5.0f, 1.0f}; GLfloat LightPosition[] = { 0.0f, 5.0f, 0.0f, 1.0f}; glClearColor( 0.25, 0.25, 0.25, 0.0 ); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient); glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, LightSpecular); glLightfv(GL_LIGHT0, GL_POSITION, LightPosition); glEnable(GL_LIGHT0); glShadeModel(GL_SMOOTH); draw_motivator(); // Draw from the master boid list for( std::vector<Boid*>::iterator it = boids.begin(); it != boids.end(); it++ ) { Boid* boid = (*it); draw_body( boid->body ); } /* // Draw Flocks Flock *flock; Boid *boid; for( std::vector<Flock*>::iterator it = flocks.begin(); it != flocks.end(); it++ ) { flock = (*it); for( std::vector<Boid*>::iterator bit = flock->members.begin(); bit != flock->members.end(); bit++ ) { boid = (*bit); draw_body( boid->body ); } } */ /* if( opt_draw_actor ) //draw_articulatedbody( articulatedbody ); draw_body( *boid ); */ /* if( opt_draw_trajectories ) { draw_trajectory( articulatedbody.trajectory, NULL ); unsigned int num_ctlpts = articulatedbody.trajectory.controlpoints.size(); for( unsigned int i = 0; i < num_ctlpts; i++ ) { ControlPoint cp = articulatedbody.trajectory.controlpoints.at( i ); Matrix4 T = Matrix4::translationMatrix( cp.position ); glLoadMatrixd( T.arrayOpenGL() ); draw_mesh( mesh_controlpt ); } } */ glutSwapBuffers(); if( GENERATE_MOVIE ) { sprintf( filename, "%s_%.04d.tif",filetitle.c_str(), frame_id ); printf( "%s\n", filename ); Utilities::writetiff( filename, "movie", 0, 0, Width, Height, COMPRESSION_NONE ); } }
void UnifiedWindow::Motion(const int x, const int y) { if(left_button_ == true) { // we want to rotate int deltaX = x - clickX_; int deltaY = y - clickY_; clickX_ = x; clickY_ = y; if ((deltaX == 0) && (deltaY == 0)) return; double axisX = deltaY; double axisY = deltaX; double axisZ = 0.0; glGetIntegerv(GL_VIEWPORT, (GLint*)window_info_); double angle = 180.0 * sqrt(static_cast<double>(deltaX * deltaX + deltaY * deltaY)) / static_cast<double>(window_info_[2] + 1); // -> calculate axis in world coordinates double wx = rotation_matrix_[0] * axisX + rotation_matrix_[1] * axisY + rotation_matrix_[ 2] * axisZ; double wy = rotation_matrix_[4] * axisX + rotation_matrix_[5] * axisY + rotation_matrix_[ 6] * axisZ; double wz = rotation_matrix_[8] * axisX + rotation_matrix_[9] * axisY + rotation_matrix_[10] * axisZ; glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadMatrixd(rotation_matrix_); glRotated(angle, wx, wy, wz); glGetDoublev(GL_MODELVIEW_MATRIX, rotation_matrix_); glPopMatrix(); } if(middle_button_ == true) { int deltaX = x - clickX_; int deltaY = y - clickY_; clickX_ = x; clickY_ = y; glGetIntegerv(GL_VIEWPORT, (GLint*)window_info_); fov_ *= static_cast<double>(window_info_[3] - deltaY) / window_info_[3]; } if(right_button_ == true) { int deltaX = x - clickX_; int deltaY = y - clickY_; clickX_ = x; clickY_ = y; //translation is always camera system double dx = deltaX; double dy = -deltaY; double dz = 0.0; glGetIntegerv(GL_VIEWPORT, (GLint*)window_info_); dx *= fc->sizeFactor * 0.2 * fov_/window_info_[3]; dy *= fc->sizeFactor * 0.2 * fov_/window_info_[3]; dz *= fc->sizeFactor * 0.2 * fov_/window_info_[3]; translation_[0] += dx; translation_[1] += dy; translation_[2] += dz; } Redisplay(); }
//--------------------------------------------------------------------------- void RenderEngineGL::SetViewMatrixd(const mat4<double>& view) { _view = view; _updatematrix(); glLoadMatrixd(_mv.GetGLMatrix()); }
PXR_NAMESPACE_OPEN_SCOPE /* static */ bool px_vp20Utils::setupLightingGL(const MHWRender::MDrawContext& context) { MStatus status; // Take into account only the 8 lights supported by the basic // OpenGL profile. const unsigned int nbLights = std::min(context.numberOfActiveLights(&status), 8u); if (status != MStatus::kSuccess) return false; if (nbLights > 0) { // Lights are specified in world space and needs to be // converted to view space. glMatrixMode(GL_MODELVIEW); glPushMatrix(); const MMatrix worldToView = context.getMatrix(MHWRender::MDrawContext::kViewMtx, &status); if (status != MStatus::kSuccess) return false; glLoadMatrixd(worldToView.matrix[0]); glEnable(GL_LIGHTING); glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); glEnable(GL_COLOR_MATERIAL) ; glEnable(GL_NORMALIZE) ; { const GLfloat ambient[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; const GLfloat specular[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1); } for (unsigned int i=0; i<nbLights; ++i) { MFloatVector direction; float intensity; MColor color; bool hasDirection; bool hasPosition; #if MAYA_API_VERSION >= 201300 // Starting with Maya 2013, getLightInformation() uses MFloatPointArray for positions MFloatPointArray positions; status = context.getLightInformation( i, positions, direction, intensity, color, hasDirection, hasPosition); const MFloatPoint &position = positions[0]; #else // Maya 2012, getLightInformation() uses MFloatPoint for position MFloatPoint position; status = context.getLightInformation( i, position, direction, intensity, color, hasDirection, hasPosition); #endif if (status != MStatus::kSuccess) return false; if (hasDirection) { if (hasPosition) { // Assumes a Maya Spot Light! const GLfloat ambient[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; const GLfloat diffuse[4] = { intensity * color[0], intensity * color[1], intensity * color[2], 1.0f }; const GLfloat pos[4] = { position[0], position[1], position[2], 1.0f }; const GLfloat dir[3] = { direction[0], direction[1], direction[2]}; glLightfv(GL_LIGHT0+i, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0+i, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0+i, GL_POSITION, pos); glLightfv(GL_LIGHT0+i, GL_SPOT_DIRECTION, dir); // Maya's default value's for spot lights. glLightf(GL_LIGHT0+i, GL_SPOT_EXPONENT, 0.0); glLightf(GL_LIGHT0+i, GL_SPOT_CUTOFF, 20.0); } else { // Assumes a Maya Directional Light! const GLfloat ambient[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; const GLfloat diffuse[4] = { intensity * color[0], intensity * color[1], intensity * color[2], 1.0f }; const GLfloat pos[4] = { -direction[0], -direction[1], -direction[2], 0.0f }; glLightfv(GL_LIGHT0+i, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0+i, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0+i, GL_POSITION, pos); glLightf(GL_LIGHT0+i, GL_SPOT_CUTOFF, 180.0); } } else if (hasPosition) { // Assumes a Maya Point Light! const GLfloat ambient[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; const GLfloat diffuse[4] = { intensity * color[0], intensity * color[1], intensity * color[2], 1.0f }; const GLfloat pos[4] = { position[0], position[1], position[2], 1.0f }; glLightfv(GL_LIGHT0+i, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0+i, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0+i, GL_POSITION, pos); glLightf(GL_LIGHT0+i, GL_SPOT_CUTOFF, 180.0); } else { // Assumes a Maya Ambient Light! const GLfloat ambient[4] = { intensity * color[0], intensity * color[1], intensity * color[2], 1.0f }; const GLfloat diffuse[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; const GLfloat pos[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; glLightfv(GL_LIGHT0+i, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0+i, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0+i, GL_POSITION, pos); glLightf(GL_LIGHT0+i, GL_SPOT_CUTOFF, 180.0); } glEnable(GL_LIGHT0+i); } glPopMatrix(); } glDisable(GL_LIGHTING); return nbLights > 0; }
void display() { // This function is called whenever it is time to render // a new frame; due to the idle()-function below, this // function will get called several times per second // Clear framebuffer & zbuffer glClearColor(0.3, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(90, 1, 0.01, 100); glMatrixMode(GL_MODELVIEW); glEnable(GL_DEPTH_TEST); glLoadIdentity(); glEnable(GL_TEXTURE_2D); glLoadMatrixd(getObjectMatrix()); // Enable Gouraud shading glShadeModel(GL_SMOOTH); // Draw polygon //glEnable(GL_CULL_FACE); //glCullFace(GL_BACK); float depth = -5; int z = 1; int zstep = 1; float ztexstep = 0.01; float hyp = 5; float textint = 0; glBindTexture(GL_TEXTURE_2D, tunnelTexture); float ztexphase = 0; for (;z <= 100; z++) { glRotatef(getElapsedTime(), 0, 0, 1); int i = 1; for(;i <= 360; i++) { //printf("fiskapa %d - ", z); //printf("%d", i); //printf("\n"); float x = cos(i*PI/180) * hyp; float y = sin(i*PI/180) * hyp; glNormal3f(0, 1, 0); float xplusone = cos((i+1)*PI/180) * hyp; float yplusone = sin((i+1)*PI/180) * hyp; glBegin(GL_POLYGON); glTexCoord2f(ztexphase, textint); glVertex3f(x, y, z); glTexCoord2f(ztexphase+ztexstep, textint); glVertex3f(x, y, z + zstep); glTexCoord2f(ztexphase+ztexstep, textint+10/360); glVertex3f(xplusone, yplusone, z + zstep); glTexCoord2f(ztexphase, textint+10/360); glVertex3f(xplusone, yplusone, z); glEnd(); textint = (textint+10/360); ztexphase += ztexstep; } } /* glBegin(GL_POLYGON); glColor3f(1, 0, 0); glVertex3f(-4.5, 0.5, 0.0); glColor3f(0, 1, 0); glVertex3f(-5,0.0, 0.0); glColor3f(0, 0, 1); glVertex3f(-5,0.0, -10.0); glColor3f(1, 0, 1); glVertex3f(-4.5, 0.5, -10.0); glColor3f(0,0.4,0.7); glVertex3f(-4.0,1.0,0.0); glColor3f(0.6,0.3,0.0); glVertex3f(-3.5,1.5,0.0); glColor3f(0.2,1.0,0.0); glVertex3f(-3.5,1.50,-10.0); glColor3f(1.0,0.4,0.4); glVertex3f(-4,1.0,-10.0); glEnd(); /* glBegin(GL_POLYGON); glColor3f(0,0.9,0.3); glVertex3f(0.1,0.1,-0.2); glColor3f(0.2,0.4,0.7); glVertex3f(0.1,0.1,0.0); glColor3f(0.5,0,0.7); glVertex3f(0.1,-0.1,0.0); glColor3f(0,0.3,0.8); glVertex3f(0.1,-0.1,-0.2); glColor3f(1,0.2,0.7); glVertex3f(0.1,0.1,-0.2); glColor3f(1,0.5,0.3); glVertex3f(0.1,-0.1,-0.2); glColor3f(0,0.9,0.7); glVertex3f(-0.1,-0.1,-0.2); glColor3f(0,0.1,0.7); glVertex3f(-0.1,0.1,-0.2); glEnd(); glBegin(GL_POLYGON); glColor3f(0.2,0.8,0.7); glVertex3f(-0.1,-0.1,0.0); glColor3f(0.6,0.1,0.2); glVertex3f(-0.1,-0.1,-0.2); glColor3f(1,0.4,0.2); glVertex3f(0.1,-0.1,-0.2); glColor3f(0.1,0.4,1); glVertex3f(0.1,-0.1,0.0); */ /* glBegin(GL_POLYGON); //framsida glColor3f(1, 0, 0); glVertex3f(-0.1, 0.1, 0.0); glColor3f(0, 1, 0); glVertex3f(-0.1,-0.1, 0.0); glColor3f(0, 0, 1); glVertex3f(0.1,-0.1, 0.0); glColor3f(1, 0, 1); glVertex3f(0.1, 0.1, 0.0); //TOP glColor3f(0, 1, 1); glVertex3f(-0.1, 0.1, 0.0); glColor3f(1, 1, 0); glVertex3f(0.1, 0.1, 0.0); glColor3f(1, 1, 1); glVertex3f(0.1,0.1,-0.2); glColor3f(0.3, 0.6, 1); glVertex3f(-0.1,0.1,-0.2); //left glColor3f(0,0.4,0.7); glVertex3f(-0.1,0.1,0.0); glColor3f(0.6,0.3,0.0); glVertex3f(-0.1,0.1,-0.2); glColor3f(0.2,1.0,0.0); glVertex3f(-0.1,-0.1,-0.2); glColor3f(1.0,0.4,0.4); glVertex3f(-0.1,-0.1,0.0); glEnd(); glBegin(GL_POLYGON); //right glColor3f(0,0.9,0.3); glVertex3f(0.1,0.1,-0.2); glColor3f(0.2,0.4,0.7); glVertex3f(0.1,0.1,0.0); glColor3f(0.5,0,0.7); glVertex3f(0.1,-0.1,0.0); glColor3f(0,0.3,0.8); glVertex3f(0.1,-0.1,-0.2); //background glColor3f(1,0.2,0.7); glVertex3f(0.1,0.1,-0.2); glColor3f(1,0.5,0.3); glVertex3f(0.1,-0.1,-0.2); glColor3f(0,0.9,0.7); glVertex3f(-0.1,-0.1,-0.2); glColor3f(0,0.1,0.7); glVertex3f(-0.1,0.1,-0.2); glEnd(); glBegin(GL_POLYGON); //bottom glColor3f(0.2,0.8,0.7); glVertex3f(-0.1,-0.1,0.0); glColor3f(0.6,0.1,0.2); glVertex3f(-0.1,-0.1,-0.2); glColor3f(1,0.4,0.2); glVertex3f(0.1,-0.1,-0.2); glColor3f(0.1,0.4,1); glVertex3f(0.1,-0.1,0.0); glEnd(); */ // Swap front- and backbuffers glutSwapBuffers(); }
//------------------------------------------------------------------------------ // Drawing Operations //------------------------------------------------------------------------------ /// Draws a mesh void draw( Mesh* mesh, Matrix4& transform ) { Matrix3 R = transform.rotation(); // backface cull Vector3 view = scene.camera.position - scene.camera.viewpoint; for( unsigned int poly_id = 0; poly_id < mesh->polygonCount( ); poly_id++ ) { Polygon* poly = mesh->polygon( poly_id ); Vector3 normal = R * poly->normal; if( Vector3::dot( view, normal ) >= 0.0 ) { Vertex* v = mesh->vertex( poly->getVertex( 0 ) ); Vector3 pt = Vector3( v->position.x(), v->position.y(), v->position.z() ); if( Vector3::dot( scene.camera.position - pt, normal ) >= 0.0 ) poly->backface = true; else poly->backface = false; } else { poly->backface = false; } } glLoadMatrixd( transform.arrayOpenGL() ); glBegin( GL_TRIANGLES ); for( unsigned int poly_id = 0; poly_id < mesh->polygonCount( ); poly_id++ ) { // Select the current polygon Polygon* poly = mesh->polygon( poly_id ); if(BACKFACE_CULL) if( poly->backface ) continue; /* GLfloat *material_Ka, *material_Kd, *material_Ks, *material_Ke, material_Se; if( poly->material != NULL ) { material_Ka = (GLfloat*)poly->material->ambient.arrayOpenGL(); material_Kd = (GLfloat*)poly->material->diffuse.arrayOpenGL(); material_Ks = (GLfloat*)poly->material->specular.arrayOpenGL(); material_Ke = (GLfloat*)poly->material->emissive.arrayOpenGL(); material_Se = (GLfloat)poly->material->shininess; glMaterialfv(GL_FRONT, GL_AMBIENT, material_Ka); glMaterialfv(GL_FRONT, GL_DIFFUSE, material_Kd); glMaterialfv(GL_FRONT, GL_SPECULAR, material_Ks); glMaterialfv(GL_FRONT, GL_EMISSION, material_Ke); glMaterialf(GL_FRONT, GL_SHININESS, material_Se); } */ glColor3d( 0.6, 0.0, 0.0 ); Vertex *v0, *v1, *v2; unsigned int verts = poly->numVertices( ); if( verts < 3 ) continue; // sanity check -> malformed poly & bad juju // the model is not tessellated, so have to tessellate for OpenGL // If poly is non-convex this won't work, but assume convex. // Select the first vertex as the root of all triangles in the poly v0 = mesh->vertex( poly->getVertex( 0 ) ); // Iterate over the rest of the vertices in the polygon up to the n-1 vert for( unsigned int poly_vert = 1; poly_vert < verts - 1; poly_vert++ ) { // select the current vertex v1 = mesh->vertex( poly->getVertex( poly_vert ) ); // and the next vertex (for n-1 case this will be n so closes the poly) v2 = mesh->vertex( poly->getVertex( poly_vert + 1 ) ); glVertex3d( v0->position.x(), v0->position.y(), v0->position.z() ); glNormal3d( v0->normal.x(), v0->normal.y(), v0->normal.z() ); //glNormal3d( poly->normal.x(), poly->normal.y(), poly->normal.z() ); glVertex3d( v1->position.x(), v1->position.y(), v1->position.z() ); glNormal3d( v1->normal.x(), v1->normal.y(), v1->normal.z() ); //glNormal3d( poly->normal.x(), poly->normal.y(), poly->normal.z() ); glVertex3d( v2->position.x(), v2->position.y(), v2->position.z() ); glNormal3d( v2->normal.x(), v2->normal.y(), v2->normal.z() ); //glNormal3d( poly->normal.x(), poly->normal.y(), poly->normal.z() ); } } glEnd(); }
//------------------------------------------------------------------------------ /// Registered OpenGL Display Callback Function void display(void) { // recompute the camera projection in case it was moved scene.camera.project(); glMatrixMode( GL_PROJECTION ); glLoadIdentity( ); glLoadMatrixd( scene.camera.projection.arrayOpenGL() ); // now process the scene glMatrixMode( GL_MODELVIEW ); glLoadIdentity( ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); Matrix4 scaling_matrix, transform; if( arrow->scale != Vector3( 1.0, 1.0, 1.0 ) ) { scaling_matrix = Matrix4::scalingMatrix( arrow->scale.x(), arrow->scale.y(), arrow->scale.z() ); } for( unsigned int i = 0; i < arrow->geometryCount(); i++ ) { Geometry* g = arrow->geometry( i ); Mesh* m = static_cast<Mesh*>(g); glPushMatrix(); m->pose.transformByQuaternion(); transform = scaling_matrix * m->pose.transform; draw( m, transform ); glPopMatrix(); } // draw normals glLineWidth( 1 ); Material material; glMaterialfv(GL_FRONT, GL_AMBIENT, (GLfloat*)material.ambient.arrayOpenGL()); glMaterialfv(GL_FRONT, GL_DIFFUSE, (GLfloat*)material.diffuse.arrayOpenGL()); glMaterialfv(GL_FRONT, GL_SPECULAR, (GLfloat*)material.specular.arrayOpenGL()); glMaterialfv(GL_FRONT, GL_EMISSION, (GLfloat*)material.emissive.arrayOpenGL()); glMaterialf(GL_FRONT, GL_SHININESS, (GLfloat)material.shininess); for( unsigned int j = 0; j < arrow->geometryCount(); j++ ) { Geometry* g = arrow->geometry( j ); Mesh* m = static_cast<Mesh*>(g); m->pose.transformByQuaternion(); transform = scaling_matrix * m->pose.transform; glLoadMatrixd( transform.arrayOpenGL() ); glBegin(GL_LINES); for( unsigned int i = 0; i < m->vertexCount(); i++ ) { Vertex* v = m->vertex( i ); Vector3 pt1 = Vector3( v->position.x(), v->position.y(), v->position.z() ); Vector3 pt2 = pt1 + v->normal; glVertex3d( pt1.x(), pt1.y(), pt1.z() ); glVertex3d( pt2.x(), pt2.y(), pt2.z() ); } glEnd(); } glutSwapBuffers(); if( GENERATE_MOVIE ) { sprintf( filename, "%s_%.04d.tif",filetitle.c_str(), frame_id ); printf( "%s\n", filename ); Utilities::writetiff( filename, "movie", 0, 0, Width, Height, COMPRESSION_NONE ); } }
// // This function is called when the window needs redrawing. // static void Display(void) { ARdouble p[16]; ARdouble m[16]; double zoom; // Select correct buffer for this context. glDrawBuffer(GL_BACK); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame. arglDispImage(gARTImage, &(gCparamLT->param), 1.0, gArglSettings); // zoom = 1.0. gARTImage = NULL; // Invalidate image data. // Projection transformation. arglCameraFrustumRH(&(gCparamLT->param), VIEW_DISTANCE_MIN, VIEW_DISTANCE_MAX, p); glMatrixMode(GL_PROJECTION); #ifdef ARDOUBLE_IS_FLOAT glLoadMatrixf(p); #else glLoadMatrixd(p); #endif glMatrixMode(GL_MODELVIEW); glEnable(GL_DEPTH_TEST); // Viewing transformation. glLoadIdentity(); // Lighting and geometry that moves with the camera should go here. // (I.e. must be specified before viewing transformations.) //none if (gPatt_found) { // Calculate the camera position relative to the marker. // Replace VIEW_SCALEFACTOR with 1.0 to make one drawing unit equal to 1.0 ARToolKit units (usually millimeters). arglCameraViewRH(gPatt_trans, m, VIEW_SCALEFACTOR); #ifdef ARDOUBLE_IS_FLOAT glLoadMatrixf(m); #else glLoadMatrixd(m); #endif // All lighting and geometry to be drawn relative to the marker goes here. // Draw the movie frame. if (gMovieImage) { glPushMatrix(); glRotatef(90.0f, 1.0f, 0.0f, 0.0f); // Place movie in x-z plane instead of x-y plane. glTranslated(-gPatt_width*0.5, 0.0f, 0.0f); // Movie origin is at lower-left of movie frame. Place this at the edge of the marker . zoom = 1.0/gMovieCparam.xsize * gPatt_width; // Scale the movie frame so that it is the same width as the marker. arglDispImageStateful(gMovieImage, &gMovieCparam, zoom, gMovieArglSettings); // Show the movie frame. glPopMatrix(); } } // gPatt_found // Any 2D overlays go here. glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, (GLdouble)windowWidth, 0, (GLdouble)windowHeight, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); // // Draw help text and mode. // if (gShowMode) { printMode(); } if (gShowHelp) { if (gShowHelp == 1) { printHelpKeys(); } } glutSwapBuffers(); }
void cubeLocatorDrawOverride::draw (const MHWRender::MDrawContext &context, const MUserData *data) { MPointArray vertices =cubeLocator::vertices () ; // get cached data float color [3] ={ 0.0f, 1.0f, 0.0f } ; float multiplier =1.0f ; const cubeLocatorData *cubeData =dynamic_cast<const cubeLocatorData *>(data) ; if ( cubeData ) multiplier =cubeData->multiplier ; // get state data MStatus status ; const MMatrix transform =context.getMatrix (MHWRender::MDrawContext::kWorldViewMtx, &status) ; if ( status != MStatus::kSuccess ) return ; const MMatrix projection =context.getMatrix (MHWRender::MDrawContext::kProjectionMtx, &status) ; if ( status != MStatus::kSuccess ) return ; const int displayStyle =context.getDisplayStyle () ; // get renderer MHWRender::MRenderer *theRenderer =MHWRender::MRenderer::theRenderer () ; if ( !theRenderer ) return ; // GL Draw if ( theRenderer->drawAPIIsOpenGL () ) { // set colour glColor3fv (color) ; // set world matrix glMatrixMode (GL_MODELVIEW) ; glPushMatrix () ; glLoadMatrixd (transform.matrix [0]) ; // set projection matrix glMatrixMode (GL_PROJECTION) ; glPushMatrix () ; glLoadMatrixd (projection.matrix [0]) ; if ( displayStyle & MHWRender::MDrawContext::kGouraudShaded ) { // See myShadedDraw glPushAttrib (GL_CURRENT_BIT) ; glBegin (GL_QUADS) ; for ( int i =0 ; i < vertices.length () - 3 ; i +=4 ) { glVertex3f (vertices [i].x * multiplier, vertices [i].y * multiplier, vertices [i].z * multiplier) ; glVertex3f (vertices [i + 1].x * multiplier, vertices [i + 1].y * multiplier, vertices [i + 1].z * multiplier) ; glVertex3f (vertices [i + 2].x * multiplier, vertices [i + 2].y * multiplier, vertices [i + 2].z * multiplier) ; glVertex3f (vertices [i + 3].x * multiplier, vertices [i + 3].y * multiplier, vertices [i + 3].z * multiplier) ; } glEnd () ; glPopAttrib () ; } if ( displayStyle & MHWRender::MDrawContext::kWireFrame ) { // See myWireFrameDraw for ( int i =0 ; i < vertices.length () - 3 ; i +=4 ) { glBegin (GL_LINE_LOOP) ; glVertex3f (vertices [i].x * multiplier, vertices [i].y * multiplier, vertices [i].z * multiplier) ; glVertex3f (vertices [i + 1].x * multiplier, vertices [i + 1].y * multiplier, vertices [i + 1].z * multiplier) ; glVertex3f (vertices [i + 2].x * multiplier, vertices [i + 2].y * multiplier, vertices [i + 2].z * multiplier) ; glVertex3f (vertices [i + 3].x * multiplier, vertices [i + 3].y * multiplier, vertices [i + 3].z * multiplier) ; glEnd () ; } } glPopMatrix () ; glMatrixMode (GL_MODELVIEW) ; glPopMatrix () ; } }
void render_ui() { LLGLState::checkStates(); glPushMatrix(); glLoadMatrixd(gGLLastModelView); glh::matrix4f saved_view = glh_get_current_modelview(); glh_set_current_modelview(glh_copy_matrix(gGLLastModelView)); { BOOL to_texture = gPipeline.canUseVertexShaders() && LLPipeline::sRenderGlow; if (to_texture) { gPipeline.renderBloom(gSnapshot); } render_hud_elements(); render_hud_attachments(); } LLGLSDefault gls_default; LLGLSUIDefault gls_ui; { gPipeline.disableLights(); } { gGL.color4f(1,1,1,1); if (gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI)) { LLFastTimer t(LLFastTimer::FTM_RENDER_UI); if (!gDisconnected) { render_ui_3d(); LLGLState::checkStates(); } render_ui_2d(); LLGLState::checkStates(); } gGL.flush(); { gViewerWindow->setup2DRender(); gViewerWindow->updateDebugText(); gViewerWindow->drawDebugText(); } LLVertexBuffer::unbind(); } glh_set_current_modelview(saved_view); glPopMatrix(); if (gDisplaySwapBuffers) { LLFastTimer t(LLFastTimer::FTM_SWAP); gViewerWindow->mWindow->swapBuffers(); } gDisplaySwapBuffers = TRUE; }
M(void, glLoadMatrixd, jobject m) { glLoadMatrixd(BUFF(GLdouble, m)); }
/** Génère l'image en cours * SUBROUTINE display(void) * * This is our main rendering subroutine, called each frame * */ void FonctionsOpenGL::display(void) { if (TheResizedImage.rows==0) //On attend que l'image soit bien réinitialisée avant de continuer return; ///C'est bon, image réinitialisée glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); ///On rend l'image dans le buffer glMatrixMode(GL_MODELVIEW); //Positionnement de la caméra glLoadIdentity(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, TheGlWindowSize.width, 0, TheGlWindowSize.height, -1.0, 5.0); glViewport(0, 0, TheGlWindowSize.width , TheGlWindowSize.height); glDisable(GL_TEXTURE_2D); glPixelZoom( 1, -1); glRasterPos3f( 0, TheGlWindowSize.height - 0.5, -1.0f ); glDrawPixels ( TheGlWindowSize.width , TheGlWindowSize.height , GL_RGB , GL_UNSIGNED_BYTE , TheResizedImage.ptr(0) ); //rend la vidéo glAccum(GL_LOAD, 0.5); ///On récupère la matrice de projection afin de faire nos rendus dans l'environnement comme si on filmait depuis la caméra glMatrixMode(GL_PROJECTION); double proj_matrix[16]; TheCameraParams.glGetProjectionMatrix(TheInputImage.size(),TheGlWindowSize,proj_matrix,0.05,facteurZoom*10); glLoadIdentity(); glLoadMatrixd(proj_matrix); glLineWidth(2); //Pour chaque marqueur (démo plus) double modelview_matrix[16]; // Afficher un cube au dessus de chaque marker /* for (unsigned int m=0;m<TheMarkers.size();m++) { TheMarkers[m].glGetModelViewMatrix(modelview_matrix); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLoadMatrixd(modelview_matrix); // axis(TheMarkerSize); glColor3f(1,0.4,0.4); glTranslatef(0, TheMarkerSize/2,0); glPushMatrix(); glutWireCube( TheMarkerSize ); glPopMatrix(); } */ //Si la planche est détecté avec assez de probabilités, on affiche l'objet if (TheBoardDetected.second>0.1) { TheBoardDetected.first.glGetModelViewMatrix(modelview_matrix); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLoadMatrixd(modelview_matrix); glColor3f(0,1,0); glTranslatef(0, TheMarkerSize/2,0); //On est pile sur le plan des markers glPushMatrix(); glEnable(GL_DEPTH_TEST); // Cache les éléments normalement cachés : c'est le Z-Buffer if (objarray[0]->id_texture!=-1) { glBindTexture(GL_TEXTURE_2D, objarray[0]->id_texture); // On active les textures glEnable(GL_TEXTURE_2D); // Texture mapping ok //printf("Textures chargées"); } else glDisable(GL_TEXTURE_2D); // Texture mapping OFF // Grossir/réduire les éléments affichés à l'écran (+ pour zoomer, - pour dézoomer, 1 pour revenir à la taille d'origine) glScalef(facteurZoom, facteurZoom, facteurZoom); glClear( GL_COLOR_BUFFER_BIT); glutSolidCube(TheMarkerSize*10); glAccum(GL_ACCUM, 0); glClear(GL_COLOR_BUFFER_BIT); // Rotation de la voiture dans le plan (xOz) glRotatef(yrot,0.0,1.0,0.0); // Translation de la voiture dans le plan (xOz) glTranslated(xpos,0.0f,zpos); // Affichage de la voiture objarray[0]->render(); glAccum(GL_ACCUM, 0.5); // Afficher théière de taille TheMarkerSize // glutWireTeapot( TheMarkerSize ); glDisable(GL_DEPTH_TEST); // Cache les éléments normalement cachés : c'est le Z-Buffer glPopMatrix(); glAccum(GL_RETURN, 1); } glutSwapBuffers(); }
void CVComplexShape::Draw() { // logToFile((f, "CVComplexShape Draw\n")); if(!m_IsVisible) return; double *vertices = exact ? scrVertices : m_getVertices(); if (arrays[aiIndices] != 0 && GetLength(arrays[aiIndices], 1) == 0 || vertices == 0 || GetLength(vertices, 1) == 0) return; glPushMatrix(); if(exact){ glMatrixMode (GL_MODELVIEW); glLoadIdentity(); glTranslated(0.0, 0.0, m_dZ); } else { // Only get exact calibration location of center // and approximate the rest of the points /* float x = XPosToScreen((float)X,(float)Y); float y = YPosToScreen((float)X,(float)Y); m_nClipped = VISWIN_IS_CLIPPED(x,y); */ float pix[2]; g_TransformCoordinatesF( m_dX, m_dY, pix, pix+1 ); m_nClipped = IS_OFF_WINDOW(pix[0],pix[1]); g_TransformGradientD(JAC,m_dX,m_dY); /* DPosToDScreen(JAC,x,y); */ // Rot 4x4, allocated by column, as in matlab // Jac, though, is only the 2x2 Jacobian ROT[0]=m_dScale*JAC[0][0]; ROT[1]=m_dScale*JAC[1][0]; ROT[4]=m_dScale*JAC[0][1]; ROT[5]=m_dScale*JAC[1][1]; ROT[12]=pix[0]; ROT[13]=pix[1]; ROT[14]=m_dZ; glMatrixMode (GL_MODELVIEW); // glLoadIdentity(); // glTranslatef((float)x,(float)y,Z); // 3: Translate // glScalef((float)scx,(float)scy,1); // 2: Scale glLoadMatrixd(ROT); // 2: Translate and Scale glRotatef((float)m_dAngle,0,0,1); // 1: Rotate About Z axis } glColor4d(m_fRGB[0],m_fRGB[1],m_fRGB[2],m_fAlpha); if (drawMode >= odmLines && drawMode <= odmLineLoop) { if (lineStipple != 0) { glLineStipple(lineStippleFactor, lineStipple); glEnable(GL_LINE_STIPPLE); } if (lineWidth != 1.0) glLineWidth((float)lineWidth); } if (drawMode == odmPoints && pointSize != 1.0) glPointSize((float)pointSize); if (drawMode >= odmTriangles && drawMode <= odmPolygon) { if (arrays[aiPolygonStipple] != 0) { glEnable(GL_POLYGON_STIPPLE); glPolygonStipple((unsigned char *)arrays[aiPolygonStipple]); } } if (vertices != 0) glEnableClientState(GL_VERTEX_ARRAY); if (arrays[aiColors ] != 0) glEnableClientState(GL_COLOR_ARRAY); if (arrays[aiEdgeFlags] != 0) glEnableClientState(GL_EDGE_FLAG_ARRAY); if (arrays[aiIndices] != 0) { if (vertices != 0) glVertexPointer(GetLength(vertices, 0), GL_DOUBLE, 0, vertices); if (arrays[aiColors] != 0) glColorPointer (GetLength(arrays[aiColors], 0), GL_DOUBLE, 0, arrays[aiColors]); // if (arrays[aiEdgeFlags] != 0) // glEdgeFlagPointer(0, arrays[aiEdgeFlags]); if (GetDim(arrays[aiIndices]) == 1 || GetLength(arrays[aiIndices], 0) == 1) glDrawElements(glDrawModeMap[drawMode], GetLength(arrays[aiIndices]), GL_UNSIGNED_INT, arrays[aiIndices]); else { int len0 = GetLength(arrays[aiIndices], 0); int len1 = GetLength(arrays[aiIndices], 1); for (int i=0; i < len1; ++i) glDrawElements(glDrawModeMap[drawMode], len0, GL_UNSIGNED_INT, ((unsigned int *)arrays[aiIndices]) + len0 * i); } } else if (vertices != 0) { int len2 = GetDim(vertices) <= 2 ? 1 : GetLength(vertices, 2); for (int i=0; i < len2; ++i) { if (vertices != 0) glVertexPointer(GetLength(vertices, 0), GL_DOUBLE, 0, vertices + GetLength(vertices, 0) * GetLength(vertices, 1) * i); if (arrays[aiColors] != 0) glColorPointer (GetLength(arrays[aiColors], 0), GL_DOUBLE, 0, arrays[aiColors] + GetLength(arrays[aiColors], 0) * GetLength(arrays[aiColors], 1) * i); // if (arrays[aiEdgeFlags] != 0) // glEdgeFlagPointer(0, arrays[aiEdgeFlags]); glDrawArrays(glDrawModeMap[drawMode], 0, GetLength(vertices, 1)); } } if (vertices != 0) glDisableClientState(GL_VERTEX_ARRAY); if (arrays[aiColors ] != 0) glDisableClientState(GL_COLOR_ARRAY); if (arrays[aiEdgeFlags] != 0) glDisableClientState(GL_EDGE_FLAG_ARRAY); if (drawMode >= odmTriangles && drawMode <= odmPolygon) { if (arrays[aiPolygonStipple] != 0) glDisable(GL_POLYGON_STIPPLE); } if (drawMode >= odmLines && drawMode <= odmLineLoop) { if (lineStipple != 0) glDisable(GL_LINE_STIPPLE); if (lineWidth != 1.0) glLineWidth(1.0); } if (drawMode == odmPoints && pointSize != 1.0) glPointSize(1.0); glPopMatrix(); }
static void draw( double trans1[3][4], double trans2[3][4], int mode ) { double gl_para[16]; GLfloat mat_ambient[] = {0.0, 0.0, 1.0, 1.0}; GLfloat mat_ambient1[] = {1.0, 0.0, 0.0, 1.0}; GLfloat mat_ambient2[] = {0.0, 1.0, 1.0, 1.0}; GLfloat mat_flash[] = {0.0, 0.0, 1.0, 1.0}; GLfloat mat_flash1[] = {1.0, 0.0, 0.0, 1.0}; GLfloat mat_flash2[] = {0.0, 1.0, 1.0, 1.0}; GLfloat mat_flash_shiny[] = {50.0}; GLfloat mat_flash_shiny1[]= {50.0}; GLfloat light_position[] = {100.0,-200.0,200.0,0.0}; GLfloat ambi[] = {0.1, 0.1, 0.1, 0.1}; GLfloat lightZeroColor[] = {0.9, 0.9, 0.9, 0.1}; argDrawMode3D(); argDraw3dCamera( 0, 0 ); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); /* load the camera transformation matrix */ glMatrixMode(GL_MODELVIEW); argConvGlpara(trans1, gl_para); glLoadMatrixd( gl_para ); argConvGlpara(trans2, gl_para); glMultMatrixd( gl_para ); if( mode == 0 ) { glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glLightfv(GL_LIGHT0, GL_AMBIENT, ambi); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash); glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny); glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); }else if(mode == 3){ glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glLightfv(GL_LIGHT0, GL_AMBIENT, ambi); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash2); glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny1); glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient2); } else{ glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glLightfv(GL_LIGHT0, GL_AMBIENT, ambi); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash1); glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny1); glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient1); } glMatrixMode(GL_MODELVIEW); glTranslatef( 0.0, 0.0, 25.0 ); if (mode == 2) glScalef(1.0,1.0,5); if (mode == 3) glScalef(1.0,0.3,0.5); if( !arDebug ) glutSolidCube(50.0); else glutWireCube(50.0); glDisable( GL_LIGHTING ); glDisable( GL_DEPTH_TEST ); }
void draw(double xOri, double yOri, double zOri,\ double xDir, double yDir, double zDir) { double gl_para[16]; GLfloat mat_ambient[] = {0.0, 0.0, 1.0, 1.0}; GLfloat mat_flash[] = {0.0, 0.0, 1.0, 1.0}; GLfloat mat_flash_shiny[] = {50.0}; GLfloat light_position[] = {100.0,-200.0,200.0,0.0}; GLfloat ambi[] = {0.1, 0.1, 0.1, 0.1}; GLfloat lightZeroColor[] = {0.9, 0.9, 0.9, 0.1}; argDrawMode3D(); argDraw3dCamera( 0, 0 ); glClearDepth( 1.0 ); glClear(GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); /* load the camera transformation matrix */ argConvGlpara(g_global.patt_trans, gl_para); glMatrixMode(GL_MODELVIEW); glLoadMatrixd( gl_para ); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glLightfv(GL_LIGHT0, GL_AMBIENT, ambi); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash); glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny); glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); glMatrixMode(GL_MODELVIEW); // ---------------------- // by aicro // draw what we like glTranslatef( 0.0, 0.0, 25.0 ); glutSolidCube(50.0); // ---------------------- // by aicro CCrashTest crashTest; crashTest.calculateAABB(-25, 0, -25, 25, 50, 25); double t = crashTest.rayIntersect(xOri, yOri, zOri, xDir, yDir, zDir); if (t != -1) { } //// draw out the ray //glBegin(GL_LINES); // glVertex3d(xOri,yOri,zOri); // glVertex3d(xDir,yDir,zDir); //glEnd(); // ---------------------- glDisable( GL_LIGHTING ); glDisable( GL_DEPTH_TEST ); }
inline void glLoadMatrix( const GLdouble * m ) { glLoadMatrixd( m ); }
void SKY_BOX::test_perlin(CVIEWptr &v) { //test if (!perlin_tex) { perlin_tex = make_shared<TEXTUREgl>( Config::JOT_ROOT() + "nprdata/other_textures/" + "perlin_tex_RGB.png" ); perlin_tex->load_texture(); } assert(perlin_tex); if (perlin_tex->load_attempt_failed()) { cerr << "SKY_BOX::test_perlin: could not load file: " << perlin_tex->file() << endl; return; } // load identity for model matrix glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); // set up to draw in XY coords: glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadMatrixd(VIEW::peek()->xypt_proj().transpose().matrix()); // set opengl state: glPushAttrib(GL_ENABLE_BIT); glDisable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); // prevents depth testing AND writing to depth buffer glDisable(GL_ALPHA_TEST); //glDisable(GL_BLEND); perlin_tex->apply_texture(); // GL_ENABLE_BIT GLfloat a = 0.5f; glColor4f(0.5, 0.5, 0.5, 1); glBegin(GL_QUADS); // draw vertices in CCW order starting at bottom left: glTexCoord2f( 0, 0); glVertex2f (-a, -a); glTexCoord2f( 1, 0); glVertex2f ( a, -a); glTexCoord2f( 1, 1); glVertex2f ( a, a); glTexCoord2f( 0, 1); glVertex2f (-a, a); glEnd(); // restore state: glPopAttrib(); // restore projection matrix glMatrixMode(GL_PROJECTION); glPopMatrix(); // restore modelview matrix glMatrixMode(GL_MODELVIEW); glPopMatrix(); }
void djvOpenGlImage::draw( const djvPixelData & data, const djvOpenGlImageOptions & options, djvOpenGlImageState * state) throw (djvError) { //DJV_DEBUG("djvOpenGlImage::draw"); //DJV_DEBUG_PRINT("data = " << data); //DJV_DEBUG_PRINT("color profile = " << options.colorProfile); RestoreState restoreState; djvOpenGlImageState defaultState; if (! state) { state = &defaultState; } const djvPixelDataInfo & info = data.info(); const int proxyScale = options.proxyScale ? djvPixelDataUtil::proxyScale(info.proxy) : 1; const djvVector2i scale = djvVectorUtil::ceil<double, int>( options.xform.scale * djvVector2f(info.size * proxyScale)); const djvVector2i scaleTmp(scale.x, data.h()); //DJV_DEBUG_PRINT("scale = " << scale); //DJV_DEBUG_PRINT("scale tmp = " << scaleTmp); // Initialize. const djvOpenGlImageFilter::FILTER filter = info.size == scale ? djvOpenGlImageFilter::NEAREST : (djvVectorUtil::area(scale) < djvVectorUtil::area(info.size) ? options.filter.min : options.filter.mag); //DJV_DEBUG_PRINT("filter min = " << options.filter.min); //DJV_DEBUG_PRINT("filter mag = " << options.filter.mag); //DJV_DEBUG_PRINT("filter = " << filter); if (! state->_init || state->_info != info || state->_options != options) { switch (filter) { case djvOpenGlImageFilter::NEAREST: case djvOpenGlImageFilter::LINEAR: { //DJV_DEBUG_PRINT("init single pass"); state->_texture->init( data.info(), djvOpenGlImageFilter::toGl(filter), djvOpenGlImageFilter::toGl(filter)); state->_shader->init( sourceVertex, sourceFragment( options.colorProfile.type, options.displayProfile, options.channel, false, 0, false)); } break; case djvOpenGlImageFilter::BOX: case djvOpenGlImageFilter::TRIANGLE: case djvOpenGlImageFilter::BELL: case djvOpenGlImageFilter::BSPLINE: case djvOpenGlImageFilter::LANCZOS3: case djvOpenGlImageFilter::CUBIC: case djvOpenGlImageFilter::MITCHELL: { //DJV_DEBUG_PRINT("init two pass"); state->_texture->init( data.info(), GL_NEAREST, GL_NEAREST); // Initialize horizontal pass. djvPixelData contrib; scaleContrib( data.w(), scale.x, filter, contrib); state->_scaleXContrib->init( contrib, GL_NEAREST, GL_NEAREST); state->_scaleXShader->init( sourceVertex, sourceFragment( options.colorProfile.type, djvOpenGlImageDisplayProfile(), static_cast<djvOpenGlImageOptions::CHANNEL>(0), true, contrib.h(), true)); // Initialize vertical pass. scaleContrib( data.h(), scale.y, filter, contrib); state->_scaleYContrib->init( contrib, GL_NEAREST, GL_NEAREST); state->_scaleYShader->init( sourceVertex, sourceFragment( static_cast<djvColorProfile::PROFILE>(0), options.displayProfile, options.channel, true, contrib.h(), false)); } break; default: break; } state->_init = true; state->_info = info; state->_options = options; } // Render. const djvPixelDataInfo::Mirror mirror( info.mirror.x ? (! options.xform.mirror.x) : options.xform.mirror.x, info.mirror.y ? (! options.xform.mirror.y) : options.xform.mirror.y); //DJV_DEBUG_PRINT("mirror = " << mirror.x << " " << mirror.y); switch (filter) { case djvOpenGlImageFilter::NEAREST: case djvOpenGlImageFilter::LINEAR: { //DJV_DEBUG_PRINT("draw single pass"); state->_shader->bind(); // Initialize color and display profiles. colorProfileInit( options, state->_shader->program(), *state->_lutColorProfile); displayProfileInit( options, state->_shader->program(), *state->_lutDisplayProfile); // Draw. activeTexture(GL_TEXTURE0); uniform1i(state->_shader->program(), "inTexture", 0); state->_texture->copy(data); state->_texture->bind(); DJV_DEBUG_OPEN_GL(glPushMatrix()); const djvMatrix3f m = djvOpenGlImageXform::xformMatrix(options.xform); //DJV_DEBUG_PRINT("m = " << m); DJV_DEBUG_OPEN_GL(glLoadMatrixd(djvMatrixUtil::matrix4(m).e)); quad(info.size, mirror, proxyScale); DJV_DEBUG_OPEN_GL(glPopMatrix()); } break; case djvOpenGlImageFilter::BOX: case djvOpenGlImageFilter::TRIANGLE: case djvOpenGlImageFilter::BELL: case djvOpenGlImageFilter::BSPLINE: case djvOpenGlImageFilter::LANCZOS3: case djvOpenGlImageFilter::CUBIC: case djvOpenGlImageFilter::MITCHELL: { //DJV_DEBUG_PRINT("draw two pass"); // Horizontal pass. djvOpenGlOffscreenBuffer buffer( djvPixelDataInfo(scaleTmp, data.pixel())); { djvOpenGlOffscreenBufferScope bufferScope(&buffer); state->_scaleXShader->bind(); colorProfileInit( options, state->_scaleXShader->program(), *state->_lutColorProfile); activeTexture(GL_TEXTURE0); uniform1i(state->_scaleXShader->program(), "inTexture", 0); state->_texture->copy(data); state->_texture->bind(); activeTexture(GL_TEXTURE1); uniform1i( state->_scaleXShader->program(), "inScaleContrib", 1); state->_scaleXContrib->bind(); glPushAttrib(GL_TRANSFORM_BIT | GL_VIEWPORT_BIT); glMatrixMode(GL_PROJECTION); glPushMatrix(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); djvOpenGlUtil::ortho(scaleTmp); glViewport(0, 0, scaleTmp.x, scaleTmp.y); quad(scaleTmp, mirror); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glPopAttrib(); } // Vertical pass. state->_scaleYShader->bind(); displayProfileInit( options, state->_scaleYShader->program(), *state->_lutDisplayProfile); activeTexture(GL_TEXTURE0); uniform1i(state->_scaleYShader->program(), "inTexture", 0); DJV_DEBUG_OPEN_GL(glBindTexture(GL_TEXTURE_2D, buffer.texture())); activeTexture(GL_TEXTURE1); uniform1i(state->_scaleYShader->program(), "inScaleContrib", 1); state->_scaleYContrib->bind(); djvOpenGlImageXform xform = options.xform; xform.scale = djvVector2f(1.0); const djvMatrix3f m = djvOpenGlImageXform::xformMatrix(xform); DJV_DEBUG_OPEN_GL(glPushMatrix()); DJV_DEBUG_OPEN_GL(glLoadMatrixd(djvMatrixUtil::matrix4(m).e)); quad(scale); DJV_DEBUG_OPEN_GL(glPopMatrix()); } break; default: break; } }
void display() { // This function is called whenever it is time to render // a new frame; due to the idle()-function below, this // function will get called several times per second // Clear framebuffer & zbuffer glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(90, 1, 0.01, 1500); glMatrixMode(GL_MODELVIEW); glEnable(GL_DEPTH_TEST); glLoadIdentity(); //gluLookAt(0,0,0,getElapsedTime(),0,-1, 0, 1, 0); glLoadMatrixd(getObjectMatrix()); // Enable Gouraud shading glShadeModel(GL_SMOOTH); // Draw polygon glEnable(GL_CULL_FACE); glCullFace(GL_BACK); //load texture glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, textureId); glBegin(GL_POLYGON); /* //size of wall float zdepth = 390.0; float xwidth = 600; float yheight = 300.0; //do the wall glColor3f(1, 1, 1); glNormal3f(0,0,1); glTexCoord2f(0, 1); glVertex3f(-xwidth, yheight, -zdepth); glTexCoord2f(0, 0); glVertex3f(-xwidth,-yheight, -zdepth); glTexCoord2f(1, 0); glVertex3f(xwidth,-yheight, -zdepth); glTexCoord2f(1, 1); glVertex3f(xwidth, yheight, -zdepth); glEnd(); */ //Scrolling through texcoords //size of wall zdepth = 590.0; xwidth = 600; yheight = 400.0; starDepth = zdepth-40; //do the wall glColor3f(1, 1, 1); glNormal3f(0,0,1); glTexCoord2f(getElapsedTime()/200, 1); glVertex3f(-xwidth, yheight, -zdepth); glTexCoord2f(getElapsedTime()/200, 0); glVertex3f(-xwidth,-yheight, -zdepth); glTexCoord2f(0.3+getElapsedTime()/200, 0); glVertex3f(xwidth,-yheight, -zdepth); glTexCoord2f(0.3+getElapsedTime()/200, 1); glVertex3f(xwidth, yheight, -zdepth); glEnd(); glDisable(GL_TEXTURE_2D); //Do the bioduk top and bot glBegin(GL_POLYGON); glColor3f(0.9,0.9,0.9); glVertex3f(-xwidth,yheight+5,-zdepth+1); glVertex3f(-xwidth,yheight,-zdepth+1); glVertex3f(xwidth,yheight,-zdepth+1); glVertex3f(xwidth,yheight+5,-zdepth+1); glEnd(); glBegin(GL_POLYGON); glColor3f(0.9,0.9,0.9); glVertex3f(-xwidth,-yheight,-zdepth+1); glVertex3f(-xwidth,-yheight-5,-zdepth+1); glVertex3f(xwidth,-yheight-5,-zdepth+1); glVertex3f(xwidth,-yheight,-zdepth+1); glEnd(); //make megaman :D glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glDisable(GL_DEPTH_TEST); glBlendFunc(GL_DST_COLOR,GL_ZERO); float textureStart =0.0; float textureFinish =1.0; float tS = textureStart; float tF = textureFinish; glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_CLAMP); glBindTexture(GL_TEXTURE_2D, megatextureId[0]); // Select The First Mask Texture glBegin(GL_QUADS); // Start Drawing A Textured Quad glTexCoord2f(tS+0.5, tS); glVertex3f(0.0, 0.0, -2.0); // Bottom Left glTexCoord2f(tF+0.5, tS); glVertex3f(1.45, 0.0, -2.0); // Bottom Right glTexCoord2f(tF, tF); glVertex3f(1.45, 1.0, -2.0);// Top Right glTexCoord2f(tS, tF); glVertex3f(0.0, 1.0, -2.0); // Top Left glEnd(); // Done Drawing The Quad /*Again we enable blending and select our texture for scene 1. We map this texture on top of it's mask. */ glBlendFunc(GL_ONE, GL_ONE); // Copy Image 1 Color To The Screen glBindTexture(GL_TEXTURE_2D, megatextureId[1]); // Select The First Image Texture glBegin(GL_QUADS); // Start Drawing A Textured Quad glTexCoord2f(tS, tS); glVertex3f(0.0f, 0.0f, -2.0f); // Bottom Left glTexCoord2f(tF, tS); glVertex3f( 1.45f, 0.0f, -2.0f); // Bottom Right glTexCoord2f(tF, tF); glVertex3f( 1.45f, 1.0f, -2.0f); // Top Right glTexCoord2f(tS, tF); glVertex3f(0.0f, 1.0f, -2.0f); // Top Left //glBegin(GL_QUADS); glEnd(); // Done Drawing The Quad glDisable(GL_TEXTURE_2D); glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); //the moving stuff :D glPushMatrix(); glTranslatef(-getElapsedTime()*50,0,0); //glRotatef(45,0,0,1); starsize = 15; starOffsetX = 0; starOffsetY = 0; //Layer 1 :D makeEmStars(); //Layer 2 :D //xwidth = 380; //yheight =100; //zdepth = 300; //makeEmStars(xwidth, yheight, zdepth, starsize); //Layer 3 :D //xwidth = 380; //yheight =100; //zdepth = 300; //makeEmStars(xwidth, yheight, zdepth); glPopMatrix(); // Swap front- and backbuffers glutSwapBuffers(); }
void display(void) { glClearColor(1.0f, 1.0f, 1.0f, 0.5f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer //background glMatrixMode(GL_PROJECTION); glPushMatrix(); gluOrtho2D(0.0,352.0,288.0,0.0); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glDisable(GL_DEPTH_TEST); if(WaitForSingleObject(ghMutex, INFINITE) == WAIT_OBJECT_0) { glDrawPixels(352,288,GL_RGB,GL_UNSIGNED_BYTE,backPxls.data); ReleaseMutex(ghMutex); } glEnable(GL_DEPTH_TEST); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); const double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; a = t*20.0; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //make camera look in the proper direction (- z axis) //gluLookAt( cam[0],cam[1],cam[2], // cam[0], cam[1], -1, // 0, 1, 0); ////glRotated(60,1,0,0); //glGetDoublev(GL_MODELVIEW_MATRIX,rot); //double xc = cam[0] - curCam[0]; //double yc = cam[1] - curCam[1]; //double zc = cam[2] - curCam[2]; //if(fabs(xc) > 0.001 || fabs(yc) > 0.001 || fabs(zc) > 0.001) { // curCam[0] += xc * t * 0.08; // curCam[1] += yc * t * 0.08; // curCam[2] += zc * t * 0.08; // //printf("move %.3f %.3f %.3f by %.5f %.5f %.5f\n",curCam[0],curCam[1],curCam[2],xc,yc,zc); //} //curCam[0] = cam[0]; curCam[1] = cam[1]; curCam[2] = cam[2]; //glTranslated(-curCam[0]+0.5,-curCam[1]+0.7,-curCam[2]); ////double _d[16]; ////glGetDoublev(GL_MODELVIEW_MATRIX,_d); //double _d[16] = { rot[0],rot[1],rot[2],0, // rot[3],rot[4],rot[5],0, // rot[6],rot[7],rot[8],0, // 0, 0, 0 ,1}; //glMultMatrixd(_d); //glRotated(180,1,0,0); double m[16] = { rot[0],-rot[3],-rot[6],0, rot[1],-rot[4],-rot[7],0, rot[2],-rot[5],-rot[8],0, cam[0],-cam[1],-cam[2],1}; glLoadMatrixd(m); /*draw features*/ glPushMatrix(); ////glScaled(((double*)(camera_matrix.ptr()))[2],((double*)(camera_matrix.ptr()))[5],1.0); //gluLookAt(0,0,-2,0,0,1,0,1,0); //glScaled(.1,.1,.1); //glBegin(GL_POINTS); glColor4d(1.0,0.0,0.0,1.0); for(unsigned int i=0;i<points1Proj.size();i++) { //for(unsigned int i=0;i<points1.size();i++) { glPushMatrix(); // //glVertex3d(points1Proj[i].x,points1Proj[i].y,points1Proj[i].z); //glTranslated(points1Proj[i].x+2.5,points1Proj[i].y+3,points1Proj[i].z-9); glTranslated(points1Proj[i].x,points1Proj[i].y,points1Proj[i].z); //glTranslated(points1[i].x,points1[i].y,0); glutSolidSphere(0.03,15,15); // //glVertex2d(points1[i].x,points1[i].y); glPopMatrix(); } //glEnd(); glPopMatrix(); /**/ /*draw plane grid.. glPushMatrix(); //move to estimated plane location gluLookAt( 0.0,0.0,-15.0, 0.0,0.0,-1.0, 0.0,1.0,0.0); glPushMatrix(); //rotate to plane normal gluLookAt( 0.0,0.0,0.0, u[0],u[1],u[2], //normal of planar surface v[0],v[1],v[2]); //glRotated(a,0,0,1); //------- draw axes of plane -------- glPushMatrix(); glTranslated(0.1,0.1,0.1); glScaled(2.0,2.0,2.0); glBegin(GL_LINES); glColor4f(1.0f,0.0f,0.0f,1.0f); //RED = X glVertex3i(0,0,0); glVertex3i(1,0,0); glColor4f(0.0f,1.0f,0.0f,1.0f); //GREEN = Y glVertex3i(0,0,0); glVertex3i(0,1,0); glColor4f(0.0f,0.0f,1.0f,1.0f); //BLUE = Z glVertex3i(0,0,0); glVertex3i(0,0,1); glEnd(); glPopMatrix(); //-------- draw plane grid --------- glScalef(0.5,0.5,0.5); glTranslatef(-5,-5,0); glColor4f(1.0f,0.0f,1.0f,1.0f); glBegin(GL_LINES); int rows = 10, columns = 10; // Horizontal lines. for (int i=0; i<=rows; i++) { glVertex2i(0, i); glVertex2i(columns, i); } // Vertical lines. for (int i=0; i<=columns; i++) { glVertex2i(i, 0); glVertex2i(i, rows); } glEnd(); glPopMatrix(); glPopMatrix(); /**/ glutSwapBuffers(); if(!running) { glutLeaveMainLoop(); } Sleep(25); }
void LLDrawPoolTree::renderTree(BOOL selecting) { LLGLState normalize(GL_NORMALIZE, TRUE); // Bind the texture for this tree. gGL.getTexUnit(sDiffTex)->bind(mTexturep.get(), TRUE); U32 indices_drawn = 0; glMatrixMode(GL_MODELVIEW); for (std::vector<LLFace*>::iterator iter = mDrawFace.begin(); iter != mDrawFace.end(); iter++) { LLFace *face = *iter; LLDrawable *drawablep = face->getDrawable(); if (drawablep->isDead() || !face->getVertexBuffer()) { continue; } face->getVertexBuffer()->setBuffer(LLDrawPoolTree::VERTEX_DATA_MASK); U16* indicesp = (U16*) face->getVertexBuffer()->getIndicesPointer(); // Render each of the trees LLVOTree *treep = (LLVOTree *)drawablep->getVObj().get(); LLColor4U color(255,255,255,255); if (!selecting || treep->mGLName != 0) { if (selecting) { S32 name = treep->mGLName; color = LLColor4U((U8)(name >> 16), (U8)(name >> 8), (U8)name, 255); } gGLLastMatrix = NULL; glLoadMatrixd(gGLModelView); //glPushMatrix(); F32 mat[16]; for (U32 i = 0; i < 16; i++) mat[i] = (F32) gGLModelView[i]; LLMatrix4 matrix(mat); // Translate to tree base HACK - adjustment in Z plants tree underground const LLVector3 &pos_agent = treep->getPositionAgent(); //glTranslatef(pos_agent.mV[VX], pos_agent.mV[VY], pos_agent.mV[VZ] - 0.1f); LLMatrix4 trans_mat; trans_mat.setTranslation(pos_agent.mV[VX], pos_agent.mV[VY], pos_agent.mV[VZ] - 0.1f); trans_mat *= matrix; // Rotate to tree position and bend for current trunk/wind // Note that trunk stiffness controls the amount of bend at the trunk as // opposed to the crown of the tree // const F32 TRUNK_STIFF = 22.f; LLQuaternion rot = LLQuaternion(treep->mTrunkBend.magVec()*TRUNK_STIFF*DEG_TO_RAD, LLVector4(treep->mTrunkBend.mV[VX], treep->mTrunkBend.mV[VY], 0)) * LLQuaternion(90.f*DEG_TO_RAD, LLVector4(0,0,1)) * treep->getRotation(); LLMatrix4 rot_mat(rot); rot_mat *= trans_mat; F32 radius = treep->getScale().magVec()*0.05f; LLMatrix4 scale_mat; scale_mat.mMatrix[0][0] = scale_mat.mMatrix[1][1] = scale_mat.mMatrix[2][2] = radius; scale_mat *= rot_mat; const F32 THRESH_ANGLE_FOR_BILLBOARD = 15.f; const F32 BLEND_RANGE_FOR_BILLBOARD = 3.f; F32 droop = treep->mDroop + 25.f*(1.f - treep->mTrunkBend.magVec()); S32 stop_depth = 0; F32 app_angle = treep->getAppAngle()*LLVOTree::sTreeFactor; F32 alpha = 1.0; S32 trunk_LOD = LLVOTree::sMAX_NUM_TREE_LOD_LEVELS; for (S32 j = 0; j < 4; j++) { if (app_angle > LLVOTree::sLODAngles[j]) { trunk_LOD = j; break; } } if(trunk_LOD >= LLVOTree::sMAX_NUM_TREE_LOD_LEVELS) { continue ; //do not render. } if (app_angle < (THRESH_ANGLE_FOR_BILLBOARD - BLEND_RANGE_FOR_BILLBOARD)) { // // Draw only the billboard // // Only the billboard, can use closer to normal alpha func. stop_depth = -1; LLFacePool::LLOverrideFaceColor clr(this, color); indices_drawn += treep->drawBranchPipeline(scale_mat, indicesp, trunk_LOD, stop_depth, treep->mDepth, treep->mTrunkDepth, 1.0, treep->mTwist, droop, treep->mBranches, alpha); } else // if (app_angle > (THRESH_ANGLE_FOR_BILLBOARD + BLEND_RANGE_FOR_BILLBOARD)) { // // Draw only the full geometry tree // //stop_depth = (app_angle < THRESH_ANGLE_FOR_RECURSION_REDUCTION); LLFacePool::LLOverrideFaceColor clr(this, color); indices_drawn += treep->drawBranchPipeline(scale_mat, indicesp, trunk_LOD, stop_depth, treep->mDepth, treep->mTrunkDepth, 1.0, treep->mTwist, droop, treep->mBranches, alpha); } //glPopMatrix(); } } }
void OpenSubdivDrawOverride::draw(const MHWRender::MDrawContext& context, const MUserData* data) { // get cached data bool isSelected = false; SubdivUserData* mesh = const_cast<SubdivUserData*>(dynamic_cast<const SubdivUserData*>(data)); if (mesh) { isSelected = mesh->fIsSelected; } // set colour static const float colorData[] = {1.0f, 0.0f, 0.0f}; static const float selectedColorData[] = {0.0f, 1.0f, 0.0f}; if(isSelected) glColor3fv(selectedColorData); else glColor3fv(colorData); MStatus status; // set world matrix glMatrixMode(GL_MODELVIEW); glPushMatrix(); MMatrix transform = context.getMatrix(MHWRender::MDrawContext::kWorldViewMtx, &status); if (status) { glLoadMatrixd(transform.matrix[0]); } // set projection matrix glMatrixMode(GL_PROJECTION); glPushMatrix(); MMatrix projection = context.getMatrix(MHWRender::MDrawContext::kProjectionMtx, &status); if (status) { glLoadMatrixd(projection.matrix[0]); } const int displayStyle = context.getDisplayStyle(); glPushAttrib( GL_CURRENT_BIT ); glPushAttrib( GL_ENABLE_BIT); if(displayStyle & MHWRender::MDrawContext::kGouraudShaded) { glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); }else if(displayStyle & MHWRender::MDrawContext::kWireFrame){ glDisable(GL_LIGHTING); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } { int vertexStride = mesh->GetVertexStride(); // int varyingStride = mesh->GetVaryingStride(); //printf("Draw. stride = %d\n", stride); glBindBuffer(GL_ARRAY_BUFFER, mesh->GetVertexBuffer()); glVertexPointer(3, GL_FLOAT, vertexStride, ((char*)(0))); glEnableClientState(GL_VERTEX_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, mesh->GetVertexBuffer()); glNormalPointer(GL_FLOAT, vertexStride, ((char*)(12))); // glBindBuffer(GL_ARRAY_BUFFER, mesh->GetVaryingBuffer()); // glNormalPointer(GL_FLOAT, varyingStride, ((char*)(0))); glEnableClientState(GL_NORMAL_ARRAY); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh->GetElementBuffer()); glDrawElements(mesh->GetPrimType(), mesh->GetNumIndices(), GL_UNSIGNED_INT, NULL); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } glPopAttrib(); glPopAttrib(); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glColor3f(1, 1, 1); }
//--------------------------------------------------------------------------- void RenderEngineGL::SetModelMatrixd(const mat4<double>& model) { _model = model; _updatematrix(); glLoadMatrixd(_mv.GetGLMatrix()); }
/*! \brief Set view Establishes viewing & projection matrices \param gv view (geoview) \param dp display (geodisplay) */ void gsd_set_view(geoview * gv, geodisplay * gd) { double up[3]; float pos[3]; int i; GLdouble modelMatrix[16]; GLint mm; /* will expand when need to check for in focus, ortho, etc. */ gsd_check_focus(gv); gsd_get_zup(gv, up); gd->aspect = GS_get_aspect(); glGetIntegerv(GL_MATRIX_MODE, &mm); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective((double).1 * (gv->fov), (double)gd->aspect, (double)gd->nearclip, (double)gd->farclip); glMatrixMode(mm); glLoadIdentity(); /* update twist parm */ glRotatef((float)(gv->twist / 10.), 0.0, 0.0, 1.0); /* OGLXXX lookat: replace UPx with vector */ gluLookAt((double)gv->from_to[FROM][X], (double)gv->from_to[FROM][Y], (double)gv->from_to[FROM][Z], (double)gv->from_to[TO][X], (double)gv->from_to[TO][Y], (double)gv->from_to[TO][Z], (double)up[X], (double)up[Y], (double)up[Z]); /* rotate to get rotation matrix and then save it*/ if (gv->rotate.do_rot) { glPushMatrix(); glLoadMatrixd(gv->rotate.rotMatrix); glRotated(gv->rotate.rot_angle, gv->rotate.rot_axes[0], gv->rotate.rot_axes[1], gv->rotate.rot_axes[2]); glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix); for (i = 0; i < 16; i++) { gv->rotate.rotMatrix[i] = modelMatrix[i]; } glPopMatrix(); } gs_get_datacenter(pos); gsd_surf2model(pos); /* translate rotation center to view center, rotate and translate back */ glTranslatef(pos[0], pos[1], pos[2]); glMultMatrixd(gv->rotate.rotMatrix); glTranslatef(-pos[0], -pos[1], -pos[2]); /* have to redefine clipping planes when view changes */ gsd_update_cplanes(); return; }
/* draw the user object */ static int draw_object( int obj_id, double gl_para[16], int collide_flag ) { GLfloat mat_ambient[] = {0.0, 0.0, 1.0, 1.0}; GLfloat mat_ambient_collide[] = {0.0, 1.0, 0.0, 1.0}; GLfloat mat_flash[] = {0.0, 0.0, 1.0, 1.0}; GLfloat mat_flash_collide[] = {1.0, 0.0, 0.0, 1.0}; GLfloat mat_flash_shiny[] = {50.0}; GLfloat light_position[] = {100.0,-200.0,200.0,0.0}; GLfloat ambi[] = {0.0, 0.1, 0.1, 0.1}; GLfloat lightZeroColor[] = {0.9, 0.9, 0.9, 0.1}; argDrawMode3D(); argDraw3dCamera( 0, 0 ); glMatrixMode(GL_MODELVIEW); glLoadMatrixd( gl_para ); /* set the material */ glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glLightfv(GL_LIGHT0, GL_AMBIENT, ambi); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor); glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny); if(collide_flag){ printf("its collided"); if (obj_id == 0) { glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash); glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); /* draw a cube */ //glTranslatef( 0.0, 0.0, 30.0 ); //glutSolidSphere(30,12,6); electron3(); } } else { printf("its not"); if (obj_id == 0) { renderBitmapString(0, 0, 0, GLUT_BITMAP_HELVETICA_18, "HYDROGEN"); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash); glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); /* draw a cube */ //glTranslatef( 0.0, 0.0, 30.0 ); //glutSolidSphere(30,12,6); glTranslatef(-50.0, -50.0, 0.0); glScaled(2, 2, 2); electron2(); } else if (obj_id == 1) { glPushMatrix(); renderBitmapString(0, 0, 0, GLUT_BITMAP_HELVETICA_18, "OXYGEN"); glPopMatrix(); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash); glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); glTranslatef(0.0, 0.0, 0.0); glScaled(3, 3, 3); electron(); } } argDrawMode2D(); return 0; }
static void render_frame (GstVisualGL * visual) { const guint16 *data; VisBuffer *lbuf, *rbuf; guint16 ldata[VISUAL_SAMPLES], rdata[VISUAL_SAMPLES]; guint i; /* Read VISUAL_SAMPLES samples per channel */ data = (const guint16 *) gst_adapter_peek (visual->adapter, VISUAL_SAMPLES * visual->bps); lbuf = visual_buffer_new_with_buffer (ldata, sizeof (ldata), NULL); rbuf = visual_buffer_new_with_buffer (rdata, sizeof (rdata), NULL); if (visual->channels == 2) { for (i = 0; i < VISUAL_SAMPLES; i++) { ldata[i] = *data++; rdata[i] = *data++; } } else { for (i = 0; i < VISUAL_SAMPLES; i++) { ldata[i] = *data; rdata[i] = *data++; } } visual_audio_samplepool_input_channel (visual->audio->samplepool, lbuf, visual->libvisual_rate, VISUAL_AUDIO_SAMPLE_FORMAT_S16, VISUAL_AUDIO_CHANNEL_LEFT); visual_audio_samplepool_input_channel (visual->audio->samplepool, rbuf, visual->libvisual_rate, VISUAL_AUDIO_SAMPLE_FORMAT_S16, VISUAL_AUDIO_CHANNEL_RIGHT); visual_object_unref (VISUAL_OBJECT (lbuf)); visual_object_unref (VISUAL_OBJECT (rbuf)); visual_audio_analyze (visual->audio); /* apply the matrices that the actor set up */ glPushAttrib (GL_ALL_ATTRIB_BITS); glMatrixMode (GL_PROJECTION); glPushMatrix (); glLoadMatrixd (visual->actor_projection_matrix); glMatrixMode (GL_MODELVIEW); glPushMatrix (); glLoadMatrixd (visual->actor_modelview_matrix); /* This line try to hacks compatiblity with libprojectM * If libprojectM version <= 2.0.0 then we have to unbind our current * fbo to see something. But it's incorrect and we cannot use fbo chainning (append other glfilters * after libvisual_gl_projectM will not work) * To have full compatibility, libprojectM needs to take care of our fbo. * Indeed libprojectM has to unbind it before the first rendering pass * and then rebind it before the final pass. It's done from 2.0.1 */ if (g_ascii_strncasecmp (gst_element_get_name (GST_ELEMENT (visual)), "visualglprojectm", 16) == 0 && !HAVE_PROJECTM_TAKING_CARE_OF_EXTERNAL_FBO) glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0); actor_negotiate (visual->display, visual); if (visual->is_enabled_gl_depth_test) { glEnable (GL_DEPTH_TEST); glDepthFunc (visual->gl_depth_func); } if (visual->is_enabled_gl_blend) { glEnable (GL_BLEND); glBlendFunc (visual->gl_blend_src_alpha, GL_ZERO); } visual_actor_run (visual->actor, visual->audio); check_gl_matrix (); glMatrixMode (GL_PROJECTION); glPopMatrix (); glMatrixMode (GL_MODELVIEW); glPopMatrix (); glPopAttrib (); glDisable (GL_DEPTH_TEST); glDisable (GL_BLEND); /*glDisable (GL_LIGHT0); glDisable (GL_LIGHTING); glDisable (GL_POLYGON_OFFSET_FILL); glDisable (GL_COLOR_MATERIAL); glDisable (GL_CULL_FACE); */ GST_DEBUG_OBJECT (visual, "rendered one frame"); }
void OpenGLHelper::setProjectionMatrix(const mat4d &value) { glMatrixMode(GL_PROJECTION); glLoadMatrixd(value); glMatrixMode(GL_MODELVIEW); }
int WaveObjLoader::loadObject(const char* filename, Cube cubeForObject) { std::vector<std::string*> coord; //read every single line of the obj file as a string std::vector<coordinate*> vertex; std::vector<face*> faces; std::vector<coordinate*> normals; //normal vectors for every face std::ifstream in(filename); //open the .obj file if(!in.is_open()) //if not opened, exit with -1 { std::cout << "Nor oepened" << std::endl; return -1; } char buf[256]; //read in every line to coord while(!in.eof()) { in.getline(buf,256); coord.push_back(new std::string(buf)); } //go through all of the elements of coord, and decide what kind of element is that for(int i=0;i<coord.size();i++) { if(coord[i]->c_str()[0]=='#') //if it is a comment (the first character is #) continue; //we don't care about that else if(coord[i]->c_str()[0]=='v' && coord[i]->c_str()[1]==' ') //if vector { float tmpx,tmpy,tmpz; sscanf(coord[i]->c_str(),"v %f %f %f",&tmpx,&tmpy,&tmpz); //read in the 3 float coordinate to tmpx,tmpy,tmpz vertex.push_back(new coordinate(tmpx,tmpy,tmpz)); //and then add it to the end of our vertex list }else if(coord[i]->c_str()[0]=='v' && coord[i]->c_str()[1]=='n') //if normal vector { float tmpx,tmpy,tmpz; //do the same thing sscanf(coord[i]->c_str(),"vn %f %f %f",&tmpx,&tmpy,&tmpz); normals.push_back(new coordinate(tmpx,tmpy,tmpz)); }else if(coord[i]->c_str()[0]=='f') //if face { int a,b,c,d,e; if(count(coord[i]->begin(),coord[i]->end(),' ')==3) //if it is a triangle (it has 3 space in it) { sscanf(coord[i]->c_str(),"f %d//%d %d//%d %d//%d",&a,&b,&c,&b,&d,&b); faces.push_back(new face(b,a,c,d)); //read in, and add to the end of the face list }else{ sscanf(coord[i]->c_str(),"f %d//%d %d//%d %d//%d %d//%d",&a,&b,&c,&b,&d,&b,&e,&b); faces.push_back(new face(b,a,c,d,e)); //do the same, except we call another constructor, and we use different pattern } } } //raw glLoadMatrixd(cubeForObject.getMatrix().getPointer()); int num; //the id for the list num=glGenLists(1); //generate a uniqe glNewList(num,GL_COMPILE); //and create it for(int i=0;i<faces.size();i++) { if(faces[i]->four) //if it's a quad draw a quad { glBegin(GL_QUADS); //basically all I do here, is use the facenum (so the number of the face) as an index for the normal, so the 1st normal owe to the first face //I subtract 1 because the index start from 0 in C++ glNormal3f(normals[faces[i]->facenum-1]->x,normals[faces[i]->facenum-1]->y,normals[faces[i]->facenum-1]->z); //draw the faces glVertex3f(vertex[faces[i]->faces[0]-1]->x,vertex[faces[i]->faces[0]-1]->y,vertex[faces[i]->faces[0]-1]->z); glVertex3f(vertex[faces[i]->faces[1]-1]->x,vertex[faces[i]->faces[1]-1]->y,vertex[faces[i]->faces[1]-1]->z); glVertex3f(vertex[faces[i]->faces[2]-1]->x,vertex[faces[i]->faces[2]-1]->y,vertex[faces[i]->faces[2]-1]->z); glVertex3f(vertex[faces[i]->faces[3]-1]->x,vertex[faces[i]->faces[3]-1]->y,vertex[faces[i]->faces[3]-1]->z); glEnd(); }else{ glBegin(GL_TRIANGLES); glNormal3f(normals[faces[i]->facenum-1]->x,normals[faces[i]->facenum-1]->y,normals[faces[i]->facenum-1]->z); glVertex3f(vertex[faces[i]->faces[0]-1]->x,vertex[faces[i]->faces[0]-1]->y,vertex[faces[i]->faces[0]-1]->z); glVertex3f(vertex[faces[i]->faces[1]-1]->x,vertex[faces[i]->faces[1]-1]->y,vertex[faces[i]->faces[1]-1]->z); glVertex3f(vertex[faces[i]->faces[2]-1]->x,vertex[faces[i]->faces[2]-1]->y,vertex[faces[i]->faces[2]-1]->z); glEnd(); } } glEndList(); //delete everything to avoid memory leaks for(int i=0;i<coord.size();i++) delete coord[i]; for(int i=0;i<faces.size();i++) delete faces[i]; for(int i=0;i<normals.size();i++) delete normals[i]; for(int i=0;i<vertex.size();i++) delete vertex[i]; return num; //return with the id }