MCPcopy Create free account
hub / github.com/TankOs/SFGUI / RenderCustomGL

Method RenderCustomGL

examples/Test.cpp:776–871  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

774}
775
776void SampleApp::RenderCustomGL() {
777 static sf::Clock clock;
778
779 glMatrixMode( GL_MODELVIEW );
780 glPushMatrix();
781 glLoadIdentity();
782
783 glTranslatef( 0.f, 0.f, -3.f );
784
785 glRotatef( clock.getElapsedTime().asSeconds() * 50.f, 1.f, 0.f, 0.f );
786 glRotatef( clock.getElapsedTime().asSeconds() * 30.f, 0.f, 1.f, 0.f );
787 glRotatef( clock.getElapsedTime().asSeconds() * 90.f, 0.f, 0.f, 1.f );
788
789 glViewport( 0, 0, static_cast<int>( std::floor( m_gl_canvas->GetAllocation().size.x + .5f ) ), static_cast<int>( std::floor( m_gl_canvas->GetAllocation().size.y + .5f ) ) );
790
791 if( !m_custom_draw_display_list ) {
792 m_custom_draw_display_list = glGenLists( 1 );
793
794 glNewList( m_custom_draw_display_list, GL_COMPILE );
795
796 glEnable( GL_DEPTH_TEST );
797 glDepthMask( GL_TRUE );
798
799 glDisable( GL_TEXTURE_2D );
800
801 glMatrixMode( GL_PROJECTION );
802 glPushMatrix();
803 glLoadIdentity();
804
805 static const auto pi = 3.1415926535897932384626433832795f;
806 static const auto fov = 90.f;
807 static const auto near_distance = 1.f;
808 static const auto far_distance = 20.f;
809
810 // We set the proper aspect ratio using the dimensions of our Canvas.
811 auto aspect = m_gl_canvas->GetAllocation().size.x / m_gl_canvas->GetAllocation().size.y;
812 auto frustum_height = std::tan( fov / 360 * pi ) * near_distance;
813 auto frustum_width = frustum_height * aspect;
814
815 glFrustum( -frustum_width, frustum_width, -frustum_height, frustum_height, near_distance, far_distance );
816
817 glBegin( GL_QUADS );
818
819 glColor3f( 0.f, 0.f, 1.f );
820 glVertex3f( -1.f, -1.f, -1.f );
821 glVertex3f( -1.f, 1.f, -1.f );
822 glVertex3f( 1.f, 1.f, -1.f );
823 glVertex3f( 1.f, -1.f, -1.f );
824
825 glColor3f( 0.f, 1.f, 0.f );
826 glVertex3f( -1.f, -1.f, 1.f );
827 glVertex3f( -1.f, 1.f, 1.f );
828 glVertex3f( 1.f, 1.f, 1.f );
829 glVertex3f( 1.f, -1.f, 1.f );
830
831 glColor3f( 0.f, 1.f, 1.f );
832 glVertex3f( -1.f, -1.f, -1.f );
833 glVertex3f( -1.f, 1.f, -1.f );

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected