void EDA_3D_CANVAS::generateFakeShadowsTextures( REPORTER* aErrorMessages, REPORTER* aActivity ) { if( m_shadow_init == true ) { return; } // Init info 3d parameters and create gl lists: CreateDrawGL_List( aErrorMessages, aActivity ); DBG( unsigned strtime = GetRunningMicroSecs() ); m_shadow_init = true; glClearColor( 0, 0, 0, 1 ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); const float zDistMax = Millimeter2iu( 3.5 ) * GetPrm3DVisu().m_BiuTo3Dunits; glOrtho( -GetPrm3DVisu().m_BoardSize.x * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f, GetPrm3DVisu().m_BoardSize.x * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f, -GetPrm3DVisu().m_BoardSize.y * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f, GetPrm3DVisu().m_BoardSize.y * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f, 0.0, zDistMax ); float zpos = GetPrm3DVisu().GetLayerZcoordBIU( F_Paste ) * GetPrm3DVisu().m_BiuTo3Dunits; // Render FRONT shadow glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glTranslatef( 0.0f, 0.0f, zpos ); glRotatef( 180.0f, 0.0f, 1.0f, 0.0f ); // move the board in order to draw it with its center at 0,0 3D coordinates glTranslatef( -GetPrm3DVisu().m_BoardPos.x * GetPrm3DVisu().m_BiuTo3Dunits, -GetPrm3DVisu().m_BoardPos.y * GetPrm3DVisu().m_BiuTo3Dunits, 0.0f ); create_and_render_shadow_buffer( &m_text_fake_shadow_front, 512, false, 1 ); zpos = GetPrm3DVisu().GetLayerZcoordBIU( B_Paste ) * GetPrm3DVisu().m_BiuTo3Dunits; // Render BACK shadow glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glTranslatef( 0.0f, 0.0f, fabs( zpos ) ); // move the board in order to draw it with its center at 0,0 3D coordinates glTranslatef( -GetPrm3DVisu().m_BoardPos.x * GetPrm3DVisu().m_BiuTo3Dunits, -GetPrm3DVisu().m_BoardPos.y * GetPrm3DVisu().m_BiuTo3Dunits, 0.0f ); create_and_render_shadow_buffer( &m_text_fake_shadow_back, 512, false, 1 ); // Render ALL BOARD shadow glMatrixMode( GL_PROJECTION ); glLoadIdentity(); // Normalization scale to convert bouding box // to normalize 3D units between -1.0 and +1.0 S3D_VERTEX v = m_fastAABBox_Shadow.Max() - m_fastAABBox_Shadow.Min(); float BoundingBoxBoardiuTo3Dunits = 2.0f / glm::max( v.x, v.y ); //float zDistance = (m_lightPos.z * zDistMax) / sqrt( (m_lightPos.z - m_fastAABBox_Shadow.Min().z) ); float zDistance = (m_lightPos.z - m_fastAABBox_Shadow.Min().z) / 3.0f; glOrtho( -v.x * BoundingBoxBoardiuTo3Dunits / 2.0f, v.x * BoundingBoxBoardiuTo3Dunits / 2.0f, -v.y * BoundingBoxBoardiuTo3Dunits / 2.0f, v.y * BoundingBoxBoardiuTo3Dunits / 2.0f, 0.0f, zDistance ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); // fits the bouding box to scale this size glScalef( BoundingBoxBoardiuTo3Dunits, BoundingBoxBoardiuTo3Dunits, 1.0f ); // Place the eye in the lowerpoint of boudingbox and turn arround and look up to the model glTranslatef( 0.0f, 0.0f, m_fastAABBox_Shadow.Min().z ); glRotatef( 180.0, 0.0f, 1.0f, 0.0f ); // move the bouding box in order to draw it with its center at 0,0 3D coordinates glTranslatef( -(m_fastAABBox_Shadow.Min().x + v.x / 2.0f), -(m_fastAABBox_Shadow.Min().y + v.y / 2.0f), 0.0f ); create_and_render_shadow_buffer( &m_text_fake_shadow_board, 512, true, 10 ); DBG( printf( " generateFakeShadowsTextures total time %f ms\n", (double) (GetRunningMicroSecs() - strtime) / 1000.0 ) ); }
void EDA_3D_CANVAS::Redraw() { // SwapBuffer requires the window to be shown before calling if( !IsShownOnScreen() ) return; wxString err_messages; WX_STRING_REPORTER errorReporter( &err_messages ); STATUS_TEXT_REPORTER activityReporter( Parent(), 0 ); // Display build time at the end of build unsigned strtime = GetRunningMicroSecs(); SetCurrent( *m_glRC ); // Set the OpenGL viewport according to the client size of this canvas. // This is done here rather than in a wxSizeEvent handler because our // OpenGL rendering context (and thus viewport setting) is used with // multiple canvases: If we updated the viewport in the wxSizeEvent // handler, changing the size of one canvas causes a viewport setting that // is wrong when next another canvas is repainted. wxSize size = GetClientSize(); InitGL(); if( isRealisticMode() && isEnabled( FL_RENDER_SHADOWS ) ) { generateFakeShadowsTextures( &errorReporter, &activityReporter ); } // *MUST* be called *after* SetCurrent( ): glViewport( 0, 0, size.x, size.y ); // clear color and depth buffers glClearColor( 0.95, 0.95, 1.0, 1.0 ); glClearStencil( 0 ); glClearDepth( 1.0 ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ); glShadeModel( GL_SMOOTH ); // Draw background glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glDisable( GL_LIGHTING ); glDisable( GL_COLOR_MATERIAL ); glDisable( GL_DEPTH_TEST ); glDisable( GL_TEXTURE_2D ); // Draw the background ( rectangle with color gradient) glBegin( GL_QUADS ); SetGLColor( GetPrm3DVisu().m_BgColor_Top, 1.0 ); glVertex2f( -1.0, 1.0 ); // Top left corner SetGLColor( GetPrm3DVisu().m_BgColor, 1.0 ); glVertex2f( -1.0,-1.0 ); // bottom left corner glVertex2f( 1.0,-1.0 ); // bottom right corner SetGLColor( GetPrm3DVisu().m_BgColor_Top, 1.0 ); glVertex2f( 1.0, 1.0 ); // top right corner glEnd(); glEnable( GL_DEPTH_TEST ); // set viewing projection glMatrixMode( GL_PROJECTION ); glLoadIdentity(); #define MAX_VIEW_ANGLE 160.0 / 45.0 if( GetPrm3DVisu().m_Zoom > MAX_VIEW_ANGLE ) GetPrm3DVisu().m_Zoom = MAX_VIEW_ANGLE; if( Parent()->ModeIsOrtho() ) { // OrthoReductionFactor is chosen to provide roughly the same size as // Perspective View const double orthoReductionFactor = 400 / GetPrm3DVisu().m_Zoom; // Initialize Projection Matrix for Ortographic View glOrtho( -size.x / orthoReductionFactor, size.x / orthoReductionFactor, -size.y / orthoReductionFactor, size.y / orthoReductionFactor, 1, 100 ); } else { // Ratio width / height of the window display double ratio_HV = (double) size.x / size.y; // Initialize Projection Matrix for Perspective View gluPerspective( 45.0f * GetPrm3DVisu().m_Zoom, ratio_HV, 1, 100 ); } // position viewer glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glTranslatef( 0.0f, 0.0f, -(m_ZBottom + m_ZTop) / 2.0f ); // Setup light sources: SetLights(); CheckGLError( __FILE__, __LINE__ ); glMatrixMode( GL_MODELVIEW ); // position viewer // transformations GLfloat mat[4][4]; // Translate motion first, so rotations don't mess up the orientation... glTranslatef( m_draw3dOffset.x, m_draw3dOffset.y, 0.0F ); build_rotmatrix( mat, GetPrm3DVisu().m_Quat ); glMultMatrixf( &mat[0][0] ); glRotatef( GetPrm3DVisu().m_Rot[0], 1.0, 0.0, 0.0 ); glRotatef( GetPrm3DVisu().m_Rot[1], 0.0, 1.0, 0.0 ); glRotatef( GetPrm3DVisu().m_Rot[2], 0.0, 0.0, 1.0 ); if( ! m_glLists[GL_ID_BOARD] || ! m_glLists[GL_ID_TECH_LAYERS] ) CreateDrawGL_List( &errorReporter, &activityReporter ); if( isEnabled( FL_AXIS ) && m_glLists[GL_ID_AXIS] ) glCallList( m_glLists[GL_ID_AXIS] ); // move the board in order to draw it with its center at 0,0 3D coordinates glTranslatef( -GetPrm3DVisu().m_BoardPos.x * GetPrm3DVisu().m_BiuTo3Dunits, -GetPrm3DVisu().m_BoardPos.y * GetPrm3DVisu().m_BiuTo3Dunits, 0.0f ); if( isEnabled( FL_MODULE ) ) { if( ! m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] ) CreateDrawGL_List( &errorReporter, &activityReporter ); } glEnable( GL_LIGHTING ); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); if( isRealisticMode() && isEnabled( FL_RENDER_TEXTURES ) ) glEnable( GL_TEXTURE_2D ); else glDisable( GL_TEXTURE_2D ); // Set material for the board glEnable( GL_COLOR_MATERIAL ); SetOpenGlDefaultMaterial(); //glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, FALSE ); // Board Body GLint shininess_value = 32; glMateriali( GL_FRONT_AND_BACK, GL_SHININESS, shininess_value ); if( isEnabled( FL_SHOW_BOARD_BODY ) ) { if( m_glLists[GL_ID_BODY] ) { glCallList( m_glLists[GL_ID_BODY] ); } } // Board // specify material parameters for the lighting model. shininess_value = 52; glMateriali( GL_FRONT_AND_BACK, GL_SHININESS, shininess_value ); glm::vec4 specular( GetPrm3DVisu().m_CopperColor.m_Red * 0.20f, GetPrm3DVisu().m_CopperColor.m_Green * 0.20f, GetPrm3DVisu().m_CopperColor.m_Blue * 0.20f, 1.0f ); glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, &specular.x ); if( m_glLists[GL_ID_BOARD] ) { glCallList( m_glLists[GL_ID_BOARD] ); } // Tech layers shininess_value = 32; glMateriali( GL_FRONT_AND_BACK, GL_SHININESS, shininess_value ); glm::vec4 specularTech( 0.0f, 0.0f, 0.0f, 1.0f ); glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, &specularTech.x ); if( m_glLists[GL_ID_TECH_LAYERS] ) { glCallList( m_glLists[GL_ID_TECH_LAYERS] ); } if( isEnabled( FL_COMMENTS ) || isEnabled( FL_ECO ) ) { if( ! m_glLists[GL_ID_AUX_LAYERS] ) CreateDrawGL_List( &errorReporter, &activityReporter ); glCallList( m_glLists[GL_ID_AUX_LAYERS] ); } //glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, TRUE ); // Draw Component Shadow if( isEnabled( FL_MODULE ) && isRealisticMode() && isEnabled( FL_RENDER_SHADOWS ) ) { glEnable( GL_CULL_FACE ); glDisable( GL_DEPTH_TEST ); glEnable( GL_COLOR_MATERIAL ) ; SetOpenGlDefaultMaterial(); glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); glEnable( GL_TEXTURE_2D ); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); if( m_glLists[GL_ID_SHADOW_FRONT] ) { glBindTexture( GL_TEXTURE_2D, m_text_fake_shadow_front ); glCallList( m_glLists[GL_ID_SHADOW_FRONT] ); } if( m_glLists[GL_ID_SHADOW_BACK] ) { glBindTexture( GL_TEXTURE_2D, m_text_fake_shadow_back ); glCallList( m_glLists[GL_ID_SHADOW_BACK] ); } glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); glEnable( GL_DEPTH_TEST ); glDisable( GL_TEXTURE_2D ); glDisable( GL_CULL_FACE ); } glEnable( GL_COLOR_MATERIAL ); SetOpenGlDefaultMaterial(); glDisable( GL_BLEND ); // Draw Solid Shapes if( isEnabled( FL_MODULE ) ) { if( ! m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] ) CreateDrawGL_List( &errorReporter, &activityReporter ); glCallList( m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] ); } glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); // Grid uses transparency: draw it after all objects if( isEnabled( FL_GRID ) ) { if( ! m_glLists[GL_ID_GRID] ) CreateDrawGL_List( &errorReporter, &activityReporter ); glCallList( m_glLists[GL_ID_GRID] ); } // Draw Board Shadow if( isRealisticMode() && isEnabled( FL_RENDER_SHADOWS ) ) { if( m_glLists[GL_ID_SHADOW_BOARD] ) { glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glColor4f( 1.0, 1.0, 1.0, 0.75f ); glEnable( GL_CULL_FACE ); glDisable( GL_COLOR_MATERIAL ); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, m_text_fake_shadow_board ); glCallList( m_glLists[GL_ID_SHADOW_BOARD] ); glDisable( GL_CULL_FACE ); glDisable( GL_TEXTURE_2D ); } } // This list must be drawn last, because it contains the // transparent gl objects, which should be drawn after all // non transparent objects if( isEnabled( FL_MODULE ) && m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT] ) { glEnable( GL_COLOR_MATERIAL ); SetOpenGlDefaultMaterial(); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glCallList( m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT] ); } // Debug bounding boxes /* glDisable( GL_BLEND ); glDisable( GL_COLOR_MATERIAL ); glDisable( GL_LIGHTING ); glColor4f( 1.0f, 0.0f, 1.0f, 1.0f ); m_fastAABBox_Shadow.GLdebug(); glColor4f( 0.0f, 1.0f, 1.0f, 1.0f ); m_boardAABBox.GLdebug(); */ SwapBuffers(); // Show calculation time if some activity was reported if( activityReporter.HasMessage() ) { // Calculation time in seconds double calculation_time = (double)( GetRunningMicroSecs() - strtime) / 1e6; activityReporter.Report( wxString::Format( _( "Build time %.3f s" ), calculation_time ) ); } else activityReporter.Report( wxEmptyString ); if( !err_messages.IsEmpty() ) wxLogMessage( err_messages ); }
void GLUI_Mouse_Interaction::draw_active_area( void ) { int orig; int win_h = glutGet( GLUT_WINDOW_HEIGHT ), win_w = glutGet(GLUT_WINDOW_WIDTH); if ( NOT glui ) return; /*putchar( 'X' ); flushout; */ orig = set_to_glut_window(); int text_height = 18; /* what a kludge */ int viewport_size = h-text_height; /*MIN(w,h); */ glMatrixMode( GL_MODELVIEW ); glPushMatrix(); glLoadIdentity(); glTranslatef( (float) win_w/2.0, (float) win_h/2.0, 0.0 ); glRotatef( 180.0, 0.0, 1.0, 0.0 ); glRotatef( 180.0, 0.0, 0.0, 1.0 ); glTranslatef( (float) -win_w/2.0, (float) -win_h/2.0, 0.0 ); glTranslatef( (float) this->x_abs + .5, (float) this->y_abs + .5, 0.0 ); glTranslatef( (float)this->w/2.0, (float)viewport_size/2.0 + 2.0 , 0.0 ); /*** Draw the interaction control's orthographic elements ***/ iaction_draw_active_area_ortho(); /*** Setup and draw the interaction control's perspective elements ***/ /*** Set the viewport to just the square of the drawing area ***/ /* glViewport( this->x_abs , glui->main_panel->h - this->y_abs - this->h,*/ /*glViewport( this->x_abs+1+(this->w/2-viewport_size/2), this->h-this->y_abs-viewport_size-1, viewport_size, viewport_size );*/ viewport_size -= 4; int offset = 0; if ( ((this->w-viewport_size) % 2) == 1 ) offset = 1; glViewport( this->x_abs + (this->w-viewport_size)/2 + offset, win_h - this->y_abs - this->h + text_height, viewport_size, viewport_size ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glFrustum( -1.0*.08, 1.0*.08, -.08, .08, .1, 8.0 ); glMatrixMode( GL_MODELVIEW ); glPushMatrix(); glLoadIdentity(); glTranslatef( 0.0, 0.0, -3.2f ); /* glutSolidTeapot( 1.0 ); */ iaction_draw_active_area_persp(); glMatrixMode( GL_MODELVIEW ); glPopMatrix(); glui->set_viewport(); glui->set_ortho_projection(); glMatrixMode( GL_MODELVIEW ); glPopMatrix(); restore_window(orig); }
/* 김연아 선수의 모션을 취하는 함수 */ void Show() { sndPlaySound(TEXT("C:\\sample4.wav"), SND_ASYNC | SND_NOSTOP); glLoadIdentity(); //CTM 초기화 /* 로봇의 기본적인 관절의 움직임 범위를 제한하는 곳 */ L_Arm_x = (-40) + sin(time2) * 60;//왼쪽 어깨의 각도시작은 -40상태에서 sin()함수를 사용하여 주기적인 움직임 설정 R_Arm_x = (-80) - L_Arm_x; //우측 어깨의 각도시작은 -80상태에서 왼쪽어깨 움직임의 반대로 설정 R_Arm_y = -abs(cos(time2) * 10); //우측팔뚝 각도조절(팔을 뻗는 움직임표현을위하여 어깨의 sin()함수와 반대인 cos()함수 사용) L_Arm_y = -abs(-cos(time2) * 10); //좌측팔뚝 각도조절(팔을 뻗는 움직임표현을위하여 어깨의 sin()함수와 반대인 cos()함수 사용) R_Leg_y = abs(-sin(time) * 30 - 30); //우측종아리 각도조절(abs절대값을 줌으로써 종아리가 앞으로 꺾이지 않는 한계점을 설정) L_Leg_y = abs(sin(time) * 30 - 30); //좌측종아리 각도조절(abs절대값을 줌으로써 종아리가 앞으로 꺾이지 않는 한계점을 설정) R_Leg_x = sin(time) * 60; //우측다리는 60도 각도까지 움직이되 sin()함수를 사용하여 주기적인 움직임 설정 L_Leg_x = -R_Leg_x; //좌측다리는 우측다리반대로 60도 각도까지 움직이되 sin()함수를 사용하여 주기적인 움직임 설정 ////////////////display//////////////// cyl = gluNewQuadric(); //실린더 객체 생성 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //초기화 glMatrixMode(GL_MODELVIEW); //모드 설정 DrawGround(); //지면 호출 glLoadIdentity(); //CTM 초기화 glRotatef(-230.0, 0, 1, 0); //y축기준으로 회전 /* 로봇이 피겨동작시 몸이 틀어지는 것을 표현 */ glRotatef(sin(time) * 7, 0, 0, 1); //z축기준으로 7도 까지 각도틀어짐 (sin()함수를 사용하여 주기적인 움직임 설정) glRotatef(sin(time) * 7, 0, 1, 0); //y축으로 7도 까지 각도틀어짐 (sin()함수를 사용하여 주기적인 움직임 설정) //로봇 몸체 각도 조절 glTranslatef(0.0, 0.18, 0.0); //y축으로 이동 glRotatef(80, 1, 0, 0); //x축 기준으로 회전 glTranslatef(0.0, 0.5, 0.0);//최초 위치 glPushMatrix(); // 처음 저장 위치 DrawBody(0, 0, 0, 0); // 몸통 함수 호출 glPopMatrix(); // 처음 저장 좌표로 돌아 간다. glPushMatrix();// 처음 저장 좌표 다시 저장 Drawneck(); // 목함수 호출 glPopMatrix(); // 처음 저장 좌표로 돌아 간다. glPushMatrix();// 처음 저장 좌표 다시 저장 //머리 위치 설정 glRotatef(-75, 1, 0, 0); //x축기준으로 회전(머리를 위쪽으로 돌리기) glTranslatef(0.0, -0.02, 0.0); //y축으로 이동 (머리 시작점) DrawHead(); // 머리 호출 glPopMatrix(); // 처음 저장 좌표로 돌아 간다. glPushMatrix();// 처음 저장 좌표 다시 저장 //우측전체팔 위치 설정 DrawR_Arm((R_Arm_y + 30), 1, 0, 0); //우측팔호출 DrawR_Hand(-(R_Arm_y - 15), 1, 0, 0); //우측팔뚝 glPopMatrix(); // 처음 저장 좌표로 돌아 간다. glPushMatrix();// 처음 저장 좌표 다시 저장 //좌측전체팔 위치 설정 glTranslatef(0.0, -0.16, -0.04);//y축,z축으로 이동(좌측팔 시작점) glRotatef(40, 0, 0, 1); //z축 기준으로 회전 DrawL_Arm((L_Arm_y + 30), 1, 0, 0); //좌측팔호출 DrawL_Hand(-(L_Arm_y - 15), 1, 0, 0); //좌측팔뚝 glPopMatrix(); // 처음 저장 좌표로 돌아 간다. glPushMatrix();// 처음 저장 좌표 다시 저장 //좌측전체 다리 위치 설정 glTranslatef(0.0, -0.45, -0.25);//y축,z축으로 이동(좌측다리 시작점) glRotatef(-90, 1, 0, 0); //x축 기준으로 회전 DrawL_Legs(-30, 1, 0, 0); //좌측다리 DrawL_foot(10, 1, 0, 0); //좌측종아리 glPopMatrix(); // 처음 저장 좌표로 돌아 간다. glPushMatrix();// 처음 저장 좌표 다시 저장 //우측전체 다리 위치 설정 glTranslatef(0.0, -0.5, -0.5);//y축,z축으로 이동(우측다리 시작점) glRotatef(-90, 1, 0, 0); //x축 기준으로 회전 DrawR_Legs(160, 1, 0, 0); //우측다리 DrawR_foot(R_Leg_y, 1, 0, 0); //우측종아리 glPopMatrix(); // 처음 저장 좌표로 돌아 간다. glutSwapBuffers(); }
BOOL Initialize () // Any GL Init Code & User Initialization Goes Here { // Start Of User Initialization GLfloat angle = 0.0f; // Set Starting Angle To Zero // #ifndef _MSC_VER GLfloat global_ambient[4] = {0.2f, 0.2f, 0.2f, 1.0f}; // Set Ambient Lighting To Fairly Dark Light (No Color) GLfloat light0pos[4] = {0.0f, 5.0f, 10.0f, 1.0f}; // Set The Light Position GLfloat light0ambient[4] = {0.2f, 0.2f, 0.2f, 1.0f}; // More Ambient Light GLfloat light0diffuse[4] = {0.3f, 0.3f, 0.3f, 1.0f}; // Set The Diffuse Light A Bit Brighter GLfloat light0specular[4] = {0.8f, 0.8f, 0.8f, 1.0f}; // Fairly Bright Specular Lighting GLfloat lmodel_ambient[4] = {0.2f,0.2f,0.2f,1.0f}; // And More Ambient Light // #else /* GLfloat global_ambient[4]; GLfloat light0pos[4]; GLfloat light0ambient[4]; GLfloat light0diffuse[4]; GLfloat light0specular[4]; GLfloat lmodel_ambient[4]; global_ambient[0]=0.2f; // Set Ambient Lighting To Fairly Dark Light (No Color) global_ambient[1]=0.2f; global_ambient[2]=0.2f; global_ambient[3]=1.0f; light0pos[0]= 0.0f; // Set The Light Position light0pos[1]= 5.0f; light0pos[2]= 10.0f; light0pos[3]= 1.0f; light0ambient[0]=0.2f; // More Ambient Light light0ambient[1]=0.2f; light0ambient[2]=0.2f; light0ambient[3]=1.0f; light0diffuse[0]=0.3f; // Set The Diffuse Light A Bit Brighter light0diffuse[1]=0.3f; light0diffuse[2]=0.3f; light0diffuse[3]=1.0f; light0specular[0]=0.8f; // Fairly Bright Specular Lighting light0specular[1]=0.8f; light0specular[2]=0.8f; light0specular[3]= 1.0f; lmodel_ambient[0]= 0.2f; // And More Ambient Light lmodel_ambient[1]= 0.2f; lmodel_ambient[2]= 0.2f; lmodel_ambient[3]= 1.0f; */ // #endif // _MSC_VER BlurTexture = EmptyTexture(); // Create Our Empty Texture glViewport(0 , 0,width ,height); // Set Up A Viewport glMatrixMode(GL_PROJECTION); // Select The Projection Matrix glLoadIdentity(); // Reset The Projection Matrix gluPerspective(50, (float)width/(float)height, 5, 2000); // Set Our Perspective glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix glLoadIdentity(); // Reset The Modelview Matrix glEnable(GL_DEPTH_TEST); // Enable Depth Testing glLightModelfv(GL_LIGHT_MODEL_AMBIENT,lmodel_ambient); // Set The Ambient Light Model glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient); // Set The Global Ambient Light Model glLightfv(GL_LIGHT0, GL_POSITION, light0pos); // Set The Lights Position glLightfv(GL_LIGHT0, GL_AMBIENT, light0ambient); // Set The Ambient Light glLightfv(GL_LIGHT0, GL_DIFFUSE, light0diffuse); // Set The Diffuse Light glLightfv(GL_LIGHT0, GL_SPECULAR, light0specular); // Set Up Specular Lighting glEnable(GL_LIGHTING); // Enable Lighting glEnable(GL_LIGHT0); // Enable Light0 glShadeModel(GL_SMOOTH); // Select Smooth Shading glMateriali(GL_FRONT, GL_SHININESS, 128); glClearColor(0.0f, 0.0f, 0.0f, 0.5); // Set The Clear Color To Black return TRUE; // Return TRUE (Initialization Successful) }
bool CRenderSystemGL::ResetRenderSystem(int width, int height, bool fullScreen, float refreshRate) { m_width = width; m_height = height; glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); CalculateMaxTexturesize(); glViewport(0, 0, width, height); glScissor(0, 0, width, height); glEnable(GL_TEXTURE_2D); glEnable(GL_SCISSOR_TEST); //ati doesn't init the texture matrix correctly //so we have to do it ourselves glMatrixMode(GL_TEXTURE); glLoadIdentity(); if (glewIsSupported("GL_ARB_multitexture")) { //clear error flags ResetGLErrors(); GLint maxtex; glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &maxtex); //some sanity checks GLenum error = glGetError(); if (error != GL_NO_ERROR) { CLog::Log(LOGERROR, "ResetRenderSystem() GL_MAX_TEXTURE_IMAGE_UNITS_ARB returned error %i", (int)error); maxtex = 3; } else if (maxtex < 1 || maxtex > 32) { CLog::Log(LOGERROR, "ResetRenderSystem() GL_MAX_TEXTURE_IMAGE_UNITS_ARB returned invalid value %i", (int)maxtex); maxtex = 3; } //reset texture matrix for all textures for (GLint i = 0; i < maxtex; i++) { glActiveTextureARB(GL_TEXTURE0 + i); glLoadIdentity(); } glActiveTextureARB(GL_TEXTURE0); } glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0f, width-1, height-1, 0.0f, -1.0f, 1.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_BLEND); // Turn Blending On glDisable(GL_DEPTH_TEST); return true; }
void TV3DManager::display(RenderArgs* renderArgs, Camera& whichCamera) { double nearZ = DEFAULT_NEAR_CLIP; // near clipping plane double farZ = DEFAULT_FAR_CLIP; // far clipping plane // left eye portal int portalX = 0; int portalY = 0; QSize deviceSize = qApp->getDeviceSize() * qApp->getRenderResolutionScale(); int portalW = deviceSize.width() / 2; int portalH = deviceSize.height(); DependencyManager::get<GlowEffect>()->prepare(renderArgs); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); Camera eyeCamera; eyeCamera.setRotation(whichCamera.getRotation()); eyeCamera.setPosition(whichCamera.getPosition()); glEnable(GL_SCISSOR_TEST); glPushMatrix(); forEachEye([&](eyeFrustum& eye){ _activeEye = &eye; glViewport(portalX, portalY, portalW, portalH); glScissor(portalX, portalY, portalW, portalH); glMatrixMode(GL_PROJECTION); glLoadIdentity(); // reset projection matrix glFrustum(eye.left, eye.right, eye.bottom, eye.top, nearZ, farZ); // set left view frustum GLfloat p[4][4]; // Really? glGetFloatv(GL_PROJECTION_MATRIX, &(p[0][0])); float cotangent = p[1][1]; GLfloat fov = atan(1.0f / cotangent); glTranslatef(eye.modelTranslation, 0.0, 0.0); // translate to cancel parallax glMatrixMode(GL_MODELVIEW); glLoadIdentity(); renderArgs->_renderSide = RenderArgs::MONO; qApp->displaySide(renderArgs, eyeCamera, false); qApp->getApplicationOverlay().displayOverlayTextureStereo(whichCamera, _aspect, fov); _activeEye = NULL; }, [&]{ // render right side view portalX = deviceSize.width() / 2; }); glPopMatrix(); glDisable(GL_SCISSOR_TEST); auto finalFbo = DependencyManager::get<GlowEffect>()->render(renderArgs); auto fboSize = finalFbo->getSize(); // Get the ACTUAL device size for the BLIT deviceSize = qApp->getDeviceSize(); glBindFramebuffer(GL_READ_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(finalFbo)); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glBlitFramebuffer(0, 0, fboSize.x, fboSize.y, 0, 0, deviceSize.width(), deviceSize.height(), GL_COLOR_BUFFER_BIT, GL_NEAREST); glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); // reset the viewport to how we started glViewport(0, 0, deviceSize.width(), deviceSize.height()); }
int main(int argc, char *argv[]) { int c; int i; GLfloat mat_specular[] = { 0.7, 0.7, 0.7, 1.0 }; GLfloat mat_shininess[] = { 40.0 }; GLfloat light_position[] = { 4.5, 0.0, 4.5, 0.0 }; glutInit(&argc, argv); num_disks = MAX_DISKS; while((c = getopt(argc, argv, "n:s:m:")) != -1) { switch (c) { case 'n': num_disks = atoi(optarg); if (num_disks < 1 || num_disks > MAX_DISKS) { num_disks = MAX_DISKS; } break; case 's': spinning = atoi(optarg) ? 1 : 0; break; case 'm': motion = atoi(optarg) ? 1 : 0; break; default: break; } } glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutCreateWindow("Hanoi"); glutDisplayFunc(display); glutVisibilityFunc(visible); glMatrixMode(GL_PROJECTION); gluPerspective(40.0, 1.0, 0.1, 10.0); glMatrixMode(GL_MODELVIEW); gluLookAt(0, 5.5, 3.5, 0, 0, 0, 0, 0, 1); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); #ifndef TOOSLOW glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); glEnable(GL_COLOR_MATERIAL); #endif #ifndef TOOSLOW glShadeModel(GL_SMOOTH); #endif glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); #ifndef TOOSLOW glLightfv(GL_LIGHT0, GL_POSITION, light_position); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); #endif glDepthFunc(GL_LEQUAL); glClearColor(0.3, 0.3, 0.3, 0.0); #ifndef TOOSLOW glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); #endif glPolygonMode(GL_FRONT, GL_FILL); glutCreateMenu(menu); glutAddMenuEntry("Toggle motion", 2); glutAddMenuEntry("Toggle spinning", 3); glutAddMenuEntry("Quit", 666); glutAttachMenu(GLUT_RIGHT_BUTTON); #if defined(GL_POLYGON_OFFSET_EXT) if (glutExtensionSupported("GL_EXT_polygon_offset")) { glPolygonOffsetEXT(0.5, 0.0); glEnable(GL_POLYGON_OFFSET_EXT); } #endif poledlist(DL_POLE); floordlist(DL_FLOOR); disks_on_poles[0].num_disks = num_disks; for (i=0; i<num_disks; i++) { diskdlist(DL_DISK+i, 0.3 + i*0.1); disks_on_poles[0].disks[num_disks-i-1] = i; disk_offset[i][Z] = 0.2*(num_disks-i-1); } /* * start hanoi instruction engine */ { int engine_args[2]; extern void engine(int *); int p[2]; prctl(PR_SETEXITSIG, SIGTERM); if (-1 == pipe(p)) { perror("can't pipe"); exit(1); } engine_args[0] = num_disks; engine_args[1] = p[1]; engine_fd = p[0]; engine_pid = sproc((void(*)(void *))engine, PR_SALL, (void *)engine_args); if (engine_pid == -1) { perror("can't sproc"); exit(1); } } glutMainLoop(); /*NOTREACHED*/ return 0; /* ANSI C requires main to return int. */ }
/** * CPaint() is used to render "all the small things". All children are * properly rendered here, with calls to SetScissor() and then to Paint(), * and although the call to SetScissor() might be unnecessary it's always * good to do things twice if you're not certain. After that Paint() of each * object is called. * * So, we have a loop that goes through the objects vector/list, then calls for * each object the SetScissor() and then Paint(). * * Prior to rendering, however, the delayedremove vector is checked out * and all objects requested are removed. * * This f. is used within Paint(); actually there should be no reason for this * function to be used except internally when writing a widget. You may be * more interested in the Paint() method. * * \sa Paint() */ void glictContainer::CPaint() { //printf("Rendering %s (child of %s)\n", objtype, parent ? parent->objtype : "NULL"); DelayedRemove(); #if 0 // below is debug code ... glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); if (glictGlobals.clippingMode==GLICT_SCISSORTEST) glDisable(GL_SCISSOR_TEST); if (glictGlobals.clippingMode==GLICT_STENCILTEST) glDisable(GL_STENCIL_TEST); glBegin(GL_LINES); glColor3f(1.0,0.0,0.0); glVertex2f(this->clipleft,this->clipbottom); glVertex2f(this->clipleft,this->cliptop); glColor3f(0.0,1.0,0.0); glVertex2f(this->clipright,this->clipbottom); glVertex2f(this->clipleft,this->clipbottom); glColor3f(0.0,0.0,1.0); glVertex2f(this->clipright,this->cliptop); glVertex2f(this->clipright,this->clipbottom); glColor3f(1.0,1.0,0.0); glVertex2f(this->clipleft,this->cliptop); glVertex2f(this->clipright,this->cliptop); glEnd(); if (glictGlobals.clippingMode==GLICT_SCISSORTEST) glEnable(GL_SCISSOR_TEST); if (glictGlobals.clippingMode==GLICT_STENCILTEST) glEnable(GL_STENCIL_TEST); glPopMatrix(); #endif if (objects.size()) { glictGlobals.Translatef(this->x + containeroffsetx - virtualpos.x, this->y + containeroffsety - virtualpos.y,0.0); std::vector<glictContainer*>::iterator it; for (it=objects.begin(); it!=objects.end(); it++) { if (!glictGlobals.drawPartialOut) { if ((*it)->GetX()+(*it)->GetWidth() > virtualpos.x + GetWidth()) continue; if ((*it)->GetY()+(*it)->GetHeight() > virtualpos.y + GetHeight()) continue; if ((*it)->GetX() < virtualpos.x ) continue; if ((*it)->GetY() < virtualpos.y ) continue; } if ((*it)->clipbottom <= (*it)->cliptop || (*it)->clipright <= (*it)->clipleft) continue; (*it)->SetScissor(); (*it)->Paint(); } glictGlobals.Translatef(-this->x - containeroffsetx + virtualpos.x, -this->y - containeroffsety + virtualpos.y,0.0); } }
void RenderScene() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // setup camera: glMatrixMode(GL_MODELVIEW); glLoadIdentity(); g_camera.SetSimpleView(); // render something glUseProgram(g_shaderLight); //float col = 0.5f+0.5f*sinf(meshAnim); //glColor3f(col, 0.0f, 1.0f-col); glColor3f(0.5f, 0.5f, 0.7f); for (unsigned int i = 0; i < g_mesh.PointCount(); ++i) { glPushMatrix(); glTranslatef(g_mesh.Point(i)->m_pos.x, g_mesh.Point(i)->m_pos.y, g_mesh.Point(i)->m_pos.z); glCallList(g_meshDisplayList); glPopMatrix(); } glColor3f(1.0f, 0.0f, 0.0f); glPushMatrix(); glTranslatef(g_sphere.m_center.x, g_sphere.m_center.y, g_sphere.m_center.z); glutSolidSphere(g_sphere.m_radius, 16, 16); glPopMatrix(); glUseProgram(0); //glColor3f(1.0f, 0.0f, 0.0f); //glBegin(GL_LINE_STRIP); //for (unsigned int i = 0; i < g_line.PointCount(); ++i) //{ // glVertex3f(g_line.Point(i)->m_pos.x, g_line.Point(i)->m_pos.y, g_line.Point(i)->m_pos.z); //} //glEnd(); // // draw ground: //glColor3f(0.8f, 0.5f, 0.3f); //glBegin(GL_QUADS); // glNormal3f(0.0f, 1.0f, 0.0f); // glVertex3f(-10.0f, 0.0f, -10.0f); // glVertex3f(-10.0f, 0.0f, 10.0f); // glVertex3f(10.0f, 0.0f, 10.0f); // glVertex3f(10.0f, 0.0f, -10.0f); //glEnd(); // draw text & fps: glColor3f(0.0f,1.0f,0.0f); utSetOrthographicProjection(g_camera.m_screenWidth, g_camera.m_screenHeight); utCalculateAndPrintFps(10, 35); utDrawText2D(10,55, "Esc - Quit"); utDrawText2D(10,70, "R - Reset"); utDrawText2D(10,85, "Space - Reset Cam"); if (MaterialPoint::s_algType == MaterialPoint::atEuler) utDrawText2D(10,100, "Euler Integration"); else utDrawText2D(10,100, "Verlet Integration"); utResetPerspectiveProjection(); glutSwapBuffers(); }
int main(int argc, char** argv) { initGL(); std::string x = getOpenGLState(false); debugPrintf("%s\n", x.c_str()); bool _endProgram = false; // Main loop do { // Event handling SDL_Event event; while (SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: _endProgram = true; break; case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_ESCAPE: _endProgram = true; break; // TODO: Add other key handlers } break; // TODO: Add other event handlers } } glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glFrustum(-1, 1, -1, 1, -2, 2); // TODO: Your rendering code goes here; replace the simple triangle below. // Use getWindowHDC() if you want to make some kind of Win32 call static double angle = 0; angle += .01; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRotatef(angle, 0, 0, 1); glBegin(GL_TRIANGLES); glColor (Color3::BLUE); glVertex(Vector3(-0.5, -0.5, -1.0)); glVertex(Vector3( 0.5, -0.5, -1.0)); glColor (Color3::YELLOW); glVertex(Vector3( 0.0, 0.5, -1.0)); glEnd(); SDL_GL_SwapBuffers(); } while (! _endProgram); SDL_Quit(); return 0; }
void a_InitGL() { glDisable(GL_LIGHT0); a_time=2.0; a_gets=0;a_timecyc=0; gendep=1.55; cameraray[0]=0;cameraray[1]=0;cameraray[2]=0; rray[0]=0;rray[1]=0;rray[2]=0; a_x=0;a_y=0;a_float_x=0;a_float_y=0;a_float_xb=0;a_float_yb=0; a_xrot=0;a_yrot=0;a_zrot=0;a_rad=0.0f; quantos=-1.0f; a_zeta=-1.0f; a_factor=10.0f; a_time=2.0f; a_waves=0; a_az=0; a_counter=0; a_mod=0; a_xa=0;a_ya=0; a_mod=0; a_xa=0;a_ya=0; a_diffuse[0]=0.2f;a_diffuse[1]=0.2f;a_diffuse[2]=0.2f;a_diffuse[3]=1.0f; a_ambient[0]=0.1f;a_ambient[1]=0.1f;a_ambient[2]=0.1f;a_ambient[3]=1.0f; a_specular[0]=.75f;a_specular[1]=.75f;a_specular[2]=.75f;a_specular[3]=1.0f; a_emission[0]=0.2f;a_emission[1]=0.2f;a_emission[2]=0.2f;a_emission[3]=1.0f; a_shininess = 10.0f; a_LightAmbient[0]=0.5f;a_LightAmbient[1]=0.5f;a_LightAmbient[2]=0.5f;a_LightAmbient[3]=1.0f; a_LightDiffuse[0]=0.5f;a_LightDiffuse[1]=0.5f;a_LightDiffuse[2]=0.5f;a_LightDiffuse[3]=1.0f; a_LightSpecular[0]=.5f;a_LightSpecular[1]=.5f;a_LightSpecular[2]=.5f;a_LightSpecular[3]=1.0f; a_LightPosition[0]=0.0f;a_LightPosition[1]=8.0f;a_LightPosition[2]=-20.0f;a_LightPosition[3]=1.0f; a_Sinus[0]=0; a_Sinus[1]=0; a_Sinus[2]=0; a_xrot=0; a_yrot=0; a_zrot=0; a_counter=0; a_rad=0.0f; quantos=-1.0f; a_zeta=-1.0f; a_factor=10.0f; a_waves=0; a_counter=0; coeff=7.1f; a_gets=0; switcher=false; gendep=1.55; camera[0]=-12.8; camera[1]=12.8; camera[2]=5; glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glShadeModel(GL_SMOOTH); glClearColor(0.0f, 0.0f, 0.0f, 0.5f); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); a_Text=new Texture[numtexs]; a_Text[1].Load("data/logoxs.raw"); a_Text[2].Load("data/white.raw"); a_Text[3].Load("data/sun2.raw"); a_Text[4].Load("data/star.raw"); glEnable (GL_LIGHTING); glEnable (GL_LIGHT1); glLightfv(GL_LIGHT1,GL_DIFFUSE,a_LightDiffuse); glLightfv(GL_LIGHT1,GL_AMBIENT,a_LightAmbient); glLightfv(GL_LIGHT1,GL_SPECULAR,a_LightSpecular); glLightfv(GL_LIGHT1,GL_POSITION,a_LightPosition); glMaterialfv(GL_FRONT,GL_DIFFUSE,a_diffuse); glMaterialfv(GL_FRONT,GL_AMBIENT,a_ambient); glMaterialfv(GL_FRONT,GL_SPECULAR,a_specular); glMaterialf(GL_FRONT,GL_SHININESS,10.0f); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glEnable(GL_TEXTURE_2D); for (a_x=0;a_x<size;a_x++) { for (a_y=0; a_y<size;a_y++) { a_points[a_x][a_y][0]=float(a_x/(1.25f*size/32)); a_points[a_x][a_y][1]=float(a_y/(1.25f*size/32)); a_points[a_x][a_y][2]=0.0; } } for (int p=0; p<a_num; p++) { parts[p].r=128+rand()%128; parts[p].g=128+rand()%128; parts[p].b=128+rand()%128; parts[p].a=-1; parts[p].angle=rand()%90; parts[p].a_mod=0.0f; parts[p].speedlim=.005+.0001*((GLfloat)(rand()%1000)); parts[p].speed=parts[p].speedlim; parts[p].a_x=0.0f; parts[p].a_y=0.0f; parts[p].z=0.0f; } a_mod=1.0; glBlendFunc(GL_SRC_ALPHA,GL_ONE); glEnable(GL_BLEND); glDisable(GL_DEPTH_TEST); a_setpart(); }
void plot( const cube& c ) { glClearColor( 0, 0, 0, 1 ); glClearDepth(1); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glEnable( GL_DEPTH_TEST ); glDepthFunc( GL_LEQUAL ); glMatrixMode( GL_PROJECTION ); glLoadIdentity( ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity( ); glOrtho( 0, 5 * c. size, 0, 4 * c. size, -1, 1 ); for( unsigned int s = 0; s < 6; ++ s ) { // We determine where to start plotting: double x, y; // Will be the position of upper left corner of // the i-th surface. switch(s) { case 0: x = 0; y = 2; break; case 1: x = 1; y = 2; break; case 2: x = 2; y = 2; break; case 3: x = 3; y = 2; break; case 4: x = 1; y = 3; break; case 5: x = 1; y = 1; break; } x = ( x + 0.5 ) * c. size; y = ( y + 0.5 ) * c. size; for( unsigned int i = 0; i < c. size; ++ i ) for( unsigned int j = 0; j < c. size; ++ j ) { // We set the color: switch( c[ cube::getside(s) ][i][j] ) { case cube::white: glColor3f( 1, 1, 1 ); break; case cube::red: glColor3f( 1, 0, 0 ); break; case cube::orange: glColor3f( 1, 0.6, 0 ); break; case cube::green: glColor3f( 0, 1, 0 ); break; case cube::blue: glColor3f( 0, 0, 1 ); break; case cube::yellow: glColor3f( 1, 1, 0 ); break; } // and we plot: glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); glBegin( GL_POLYGON ); glVertex2f( x + j, y - i ); glVertex2f( x + j, y - i - 0.8 ); glVertex2f( x + j + 0.8, y - i - 0.8 ); glVertex2f( x + j + 0.8, y - i ); glEnd( ); } } glFlush( ); }
int main(int argc, char **argv) { int width = 320, height = 240; int i; char *name; glutInitWindowSize(width, height); glutInit(&argc, argv); /* process commmand line args */ for (i = 1; i < argc; ++i) { if (!strcmp("-db", argv[i])) { useDB = !useDB; } else { usage(); } } /* choose visual */ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); name = "MOTH - by Bob Doyle"; glutCreateWindow(name); glutKeyboardFunc(keyboard); myInit(); /* initialize objects in scene */ glutDisplayFunc(display); glutVisibilityFunc(visible); glutCreateMenu(menu_select); glutAddMenuEntry("Start motion", 1); glutAddMenuEntry("Stop motion", 2); glutAddMenuEntry("Quit", 5); glutAddMenuEntry("Drink Ed's beer", 5); glutAttachMenu(GLUT_RIGHT_BUTTON); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-.9, .9, -.9, .9, 1.0, 35.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); #if 0 glTranslatef(0.0, 0.0, mvt_zi); #endif glEnable(GL_NORMALIZE); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); /* double your fun */ glShadeModel(GL_SMOOTH); glDepthFunc(GL_LESS); glDepthMask(GL_TRUE); glEnable(GL_DEPTH_TEST); myInit(); /* initialize objects in scene */ glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }
void workshopScene::render(sceneInfo &info) { glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glFrustum((-1.f * info.width) / info.height, (1.f * info.width) / info.height, -1.f, 1.f, 1.f, 1000.f); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); btQuaternion invrotate = camera.orientation.inverse(); glRotatef(invrotate.getAngle() * RAD_TO_DEGREES, invrotate.getAxis().getX(), invrotate.getAxis().getY(), invrotate.getAxis().getZ()); glTranslatef(-camera.position.getX(), -camera.position.getY(), -camera.position.getZ()); GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat mat_shininess[] = { 50.0 }; GLfloat light_position[] = { 1.2, 1.1, 1.0, 0.0 }; glShadeModel (GL_SMOOTH); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glEnable(GL_COLOR_MATERIAL); glColor3f(1.f, 1.f, 1.f); glEnable(GL_CULL_FACE); gWorld->render(); if (axisHasFirst) { glColor3f(1, 0, 0); btTransform trans = ((btRigidBody*)(axisResult.m_collisionObject))->getCenterOfMassTransform(); btVector3 start = trans * axisFirstPivot; btVector3 end = trans * (axisFirstPivot + axisFirstNormal * 0.5); glBegin(GL_LINES); glVertex3f(start.getX(), start.getY(), start.getZ()); glVertex3f(end.getX(), end.getY(), end.getZ()); glEnd(); } glPushAttrib(GL_ENABLE_BIT); glDisable(GL_CULL_FACE); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.f, info.width, info.height, 0.f, -1.f, 1.f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor3f(1.f, 1.f, 1.f); panel.draw(0, UI_SIZE + 16, info.height, 0); glPushAttrib(GL_SCISSOR_BIT); glEnable(GL_SCISSOR_TEST); glScissor(8, 8, UI_SIZE, info.height - 16); for (unsigned int i = 0; i < thumbnails.size(); i++) { int basex = 8; int basey = 8 + (UI_SIZE + 8) * i; if (i == selectedItem) glColor3f(1.f, 1.f, 0.5f); else glColor3f(1.f, 1.f, 1.f); button.draw(basex, basex + UI_SIZE, basey + UI_SIZE, basey); glBindTexture(GL_TEXTURE_2D, thumbnails[i]); texturedQuad(basex + 8, basex + (UI_SIZE - 8), basey + (UI_SIZE - 8), basey + 8); } glPopAttrib(); panel.draw(UI_SIZE + 16, info.width, info.height, info.height - UI_SMALL - 16); glColor3f(1.f, 1.f, 1.f); for (unsigned int i = 0; i < tooltextures.size(); i++) { int basex = UI_SIZE + 16 + 8 + (UI_SMALL + 8) * i; int basey = info.height - 8 - UI_SMALL; if (i == selectedTool) glColor3f(1.f, 1.f, 0.5f); else glColor3f(1.f, 1.f, 1.f); button.draw(basex, basex + UI_SMALL, basey + UI_SMALL, basey); glBindTexture(GL_TEXTURE_2D, tooltextures[i]); texturedQuad(basex + 8, basex + UI_SMALL - 8, basey + UI_SMALL - 8, basey + 8); } glColor3f(1.f, 1.f, 1.f); if (info.captureMouse) { if (mousevelx * mousevelx + mousevely * mousevely < 1.f) glColor3f(1, 0, 0); glBindTexture(GL_TEXTURE_2D, cursor); texturedQuad(cursorx, cursorx + 20, cursory + 20, cursory); glBindTexture(GL_TEXTURE_2D, 0); glBegin(GL_LINES); glVertex2f(cursorx, cursory); glVertex2f(cursorx + mousevelx, cursory + mousevely); glEnd(); } if (mousevelx * mousevelx + mousevely * mousevely < 1.f && mouseRayCallback.hasHit()) showBubble(cursorx, cursory, gWorld->findObj((btRigidBody*)mouseRayCallback.m_collisionObject)->tag); /*glBindTexture(GL_TEXTURE_2D, font); info.keybuffer.push_back(0); print(100, 100, &info.keybuffer[0]); glBindTexture(GL_TEXTURE_2D, stbfont); texturedQuad(100, 200, 500, 400); stbprint(100, 300, &info.keybuffer[0]); info.keybuffer.erase(info.keybuffer.end() - 1);*/ glPopAttrib(); }
void LLDrawPoolTree::renderTree(BOOL selecting) { LLGLState normalize(GL_NORMALIZE, TRUE); // Bind the texture for this tree. LLViewerImage::bindTexture(mTexturep,sDiffTex); if (mTexturep) { if (mTexturep->getClampS()) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); } if (mTexturep->getClampT()) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); } } 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->mVertexBuffer.isNull()) { continue; } face->mVertexBuffer->setBuffer(LLDrawPoolTree::VERTEX_DATA_MASK); U32* indicesp = (U32*) face->mVertexBuffer->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); } glPushMatrix(); // 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); // Rotate to tree position F32 angle_radians, x, y, z; treep->getRotation().getAngleAxis(&angle_radians, &x, &y, &z); glRotatef(angle_radians * RAD_TO_DEG, x, y, z); // Rotate 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 // glRotatef(90.f, 0, 0, 1); const F32 TRUNK_STIFF = 22.f; glRotatef(treep->mTrunkBend.magVec()*TRUNK_STIFF, treep->mTrunkBend.mV[VX], treep->mTrunkBend.mV[VY], 0); F32 radius = treep->getScale().magVec()*0.5f; radius *= 0.1f; glScalef(radius, radius, radius); 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 = 0; for (S32 j = 0; j < 4; j++) { if (app_angle > LLVOTree::sLODAngles[j]) { trunk_LOD = j; break; } } 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(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(indicesp, trunk_LOD, stop_depth, treep->mDepth, treep->mTrunkDepth, 1.0, treep->mTwist, droop, treep->mBranches, alpha); } glPopMatrix(); } } if (mTexturep) { if (mTexturep->getClampS()) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); } if (mTexturep->getClampT()) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } } addIndicesDrawn(indices_drawn); }
void Cube::draw(DrawData& data) { //float halfSize = size/2.0; //Apply the material properties //From here forward anything drawn will be drawn with this material //material.apply(); //Set the OpenGL Matrix mode to ModelView (used when drawing geometry) glMatrixMode(GL_MODELVIEW); //Push a save state onto the matrix stack, and multiply in the toWorld matrix glPushMatrix(); glMultMatrixf(toWorld.ptr()); //Make cube! //Note: The glBegin, and glEnd should always be as close to the glNormal/glVertex calls as possible //These are special calls that 'freeze' many internal states of OpenGL. //Once the glBegin state is active many of the calls made to OpenGL (like glMultMatrixf) will be IGNORED! //As a good habit, only call glBegin just before you need to draw, and call end just after you finish /* glBegin(GL_QUADS); // Draw front face: glNormal3f(0.0, 0.0, 1.0); glVertex3f(-halfSize, halfSize, halfSize); glVertex3f( halfSize, halfSize, halfSize); glVertex3f( halfSize, -halfSize, halfSize); glVertex3f(-halfSize, -halfSize, halfSize); // Draw left side: glNormal3f(-1.0, 0.0, 0.0); glVertex3f(-halfSize, halfSize, halfSize); glVertex3f(-halfSize, halfSize, -halfSize); glVertex3f(-halfSize, -halfSize, -halfSize); glVertex3f(-halfSize, -halfSize, halfSize); // Draw right side: glNormal3f(1.0, 0.0, 0.0); glVertex3f( halfSize, halfSize, halfSize); glVertex3f( halfSize, halfSize, -halfSize); glVertex3f( halfSize, -halfSize, -halfSize); glVertex3f( halfSize, -halfSize, halfSize); // Draw back face: glNormal3f(0.0, 0.0, -1.0); glVertex3f(-halfSize, halfSize, -halfSize); glVertex3f( halfSize, halfSize, -halfSize); glVertex3f( halfSize, -halfSize, -halfSize); glVertex3f(-halfSize, -halfSize, -halfSize); // Draw top side: glNormal3f(0.0, 1.0, 0.0); glVertex3f(-halfSize, halfSize, halfSize); glVertex3f( halfSize, halfSize, halfSize); glVertex3f( halfSize, halfSize, -halfSize); glVertex3f(-halfSize, halfSize, -halfSize); // Draw bottom side: glNormal3f(0.0, -1.0, 0.0); glVertex3f(-halfSize, -halfSize, -halfSize); glVertex3f( halfSize, -halfSize, -halfSize); glVertex3f( halfSize, -halfSize, halfSize); glVertex3f(-halfSize, -halfSize, halfSize); glEnd(); */ //The above glBegin, glEnd, glNormal and glVertex calls can be replaced with a glut convenience function glutSolidCube(size); //Pop the save state off the matrix stack //This will undo the multiply we did earlier glPopMatrix(); }
//---------------------------------------------------------- void ofGLRenderer::setupScreenPerspective(float width, float height, int orientation, bool vFlip, float fov, float nearDist, float farDist) { if(width == 0) width = ofGetWidth(); if(height == 0) height = ofGetHeight(); if( orientation == 0 ) orientation = ofGetOrientation(); float w = width; float h = height; //we do this because ofGetWidth and ofGetHeight return orientated widths and height //for the camera we need width and height of the actual screen if( orientation == OF_ORIENTATION_90_LEFT || orientation == OF_ORIENTATION_90_RIGHT ){ h = width; w = height; } float eyeX = w / 2; float eyeY = h / 2; float halfFov = PI * fov / 360; float theTan = tanf(halfFov); float dist = eyeY / theTan; float aspect = (float) w / h; if(nearDist == 0) nearDist = dist / 10.0f; if(farDist == 0) farDist = dist * 10.0f; glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(fov, aspect, nearDist, farDist); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(eyeX, eyeY, dist, eyeX, eyeY, 0, 0, 1, 0); //note - theo checked this on iPhone and Desktop for both vFlip = false and true switch(orientation) { case OF_ORIENTATION_180: glRotatef(-180, 0, 0, 1); if(vFlip){ glScalef(1, -1, 1); glTranslatef(-width, 0, 0); }else{ glTranslatef(-width, -height, 0); } break; case OF_ORIENTATION_90_RIGHT: glRotatef(-90, 0, 0, 1); if(vFlip){ glScalef(-1, 1, 1); }else{ glScalef(-1, -1, 1); glTranslatef(0, -height, 0); } break; case OF_ORIENTATION_90_LEFT: glRotatef(90, 0, 0, 1); if(vFlip){ glScalef(-1, 1, 1); glTranslatef(-width, -height, 0); }else{ glScalef(-1, -1, 1); glTranslatef(-width, 0, 0); } break; case OF_ORIENTATION_DEFAULT: default: if(vFlip){ glScalef(1, -1, 1); glTranslatef(0, -height, 0); } break; } }
// render terrain void Terrain::render (float x, float z) { // multitexturing functions glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC) SDL_GL_GetProcAddress("glActiveTextureARB"); glMultiTexCoord2fARB = (PFNGLMULTITEXCOORD2FARBPROC) SDL_GL_GetProcAddress("glMultiTexCoord2fARB"); // enable multitexturing glActiveTextureARB (GL_TEXTURE0_ARB); glEnable (GL_TEXTURE_2D); tm -> setTexture (TERRAIN_GREEN); // carica la texture del terreno glActiveTextureARB (GL_TEXTURE1_ARB); glEnable (GL_TEXTURE_2D); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); glTexEnvi (GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2); tm -> setTexture (TERRAIN_DETAIL); // carica la texture del dettaglio // scala la seconda texture (quella del dettaglio) glMatrixMode (GL_TEXTURE); // entra nel modello delle texture glLoadIdentity (); // resetta la matrice corrente e scala la texture glScalef (TEXTURE_DATAIL, TEXTURE_DATAIL, 1); glMatrixMode (GL_MODELVIEW); // torna alla matrice del modello (NORMALE) // draw bool poly_is_near = false; static float res_to_check = res; glBegin (GL_TRIANGLES); for (int loop = 0; loop < num_vert; loop += 4) { glNormal3fv (&normal[loop/4].x); // normal // controlla se il poligono è vicino if ( fabs(vertex[loop].x - x) < res_to_check || fabs(vertex[loop+1].x - x) < res_to_check || fabs(vertex[loop+2].x - x) < res_to_check || fabs(vertex[loop+3].x - x) < res_to_check) if ( fabs(vertex[loop].z - z) < res_to_check || fabs(vertex[loop+1].z - z) < res_to_check || fabs(vertex[loop+2].z - z) < res_to_check || fabs(vertex[loop+3].z - z) < res_to_check) poly_is_near = true; // triangle 1 - check frustum if ( poly_is_near || frustum -> pointInFrustum(vertex[loop].x, vertex[loop].y, vertex[loop].z) || frustum -> pointInFrustum(vertex[loop+1].x, vertex[loop+1].y, vertex[loop+1].z) || frustum -> pointInFrustum(vertex[loop+2].x, vertex[loop+2].y, vertex[loop+2].z)) { // draw triangle glMultiTexCoord2fARB (GL_TEXTURE0_ARB, texcoord[loop].u, texcoord[loop].v); glMultiTexCoord2fARB (GL_TEXTURE1_ARB, texcoord[loop].u, texcoord[loop].v); glVertex3fv (&vertex[loop].x); // vertex glMultiTexCoord2fARB (GL_TEXTURE0_ARB, texcoord[loop+1].u, texcoord[loop+1].v); glMultiTexCoord2fARB (GL_TEXTURE1_ARB, texcoord[loop+1].u, texcoord[loop+1].v); glVertex3fv (&vertex[loop+1].x); // vertex glMultiTexCoord2fARB (GL_TEXTURE0_ARB, texcoord[loop+2].u, texcoord[loop+2].v); glMultiTexCoord2fARB (GL_TEXTURE1_ARB, texcoord[loop+2].u, texcoord[loop+2].v); glVertex3fv (&vertex[loop+2].x); // vertex } // triangle 2 - check frustum if ( poly_is_near || frustum -> pointInFrustum(vertex[loop].x, vertex[loop].y, vertex[loop].z) || frustum -> pointInFrustum(vertex[loop+2].x, vertex[loop+2].y, vertex[loop+2].z) || frustum -> pointInFrustum(vertex[loop+3].x, vertex[loop+3].y, vertex[loop+3].z)) { // draw triangle glMultiTexCoord2fARB (GL_TEXTURE0_ARB, texcoord[loop].u, texcoord[loop].v); glMultiTexCoord2fARB (GL_TEXTURE1_ARB, texcoord[loop].u, texcoord[loop].v); glVertex3fv (&vertex[loop].x); // vertex glMultiTexCoord2fARB (GL_TEXTURE0_ARB, texcoord[loop+2].u, texcoord[loop+2].v); glMultiTexCoord2fARB (GL_TEXTURE1_ARB, texcoord[loop+2].u, texcoord[loop+2].v); glVertex3fv (&vertex[loop+2].x); // vertex glMultiTexCoord2fARB (GL_TEXTURE0_ARB, texcoord[loop+3].u, texcoord[loop+3].v); glMultiTexCoord2fARB (GL_TEXTURE1_ARB, texcoord[loop+3].u, texcoord[loop+3].v); glVertex3fv (&vertex[loop+3].x); // vertex } } glEnd (); // disable multitexturing glActiveTextureARB (GL_TEXTURE1_ARB); glDisable (GL_TEXTURE_2D); glActiveTextureARB (GL_TEXTURE0_ARB); glDisable (GL_TEXTURE_2D); }