Exemple #1
0
TopicGraph::TopicGraph(QObject *parent)
    :GraphBase(parent)
{
    ConstructScene();
}
/**
 * Main 
 */
int main(int argc, char** argv)
{
   // Set up depth buffer and double buffering
   glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
   glutInitWindowPosition(100, 100);
   glutInitWindowSize(640, 480);
   glutInit(&argc, argv);

   // Set callback methods
   glutCreateWindow("Phong Shading / Shaders Example");
   glutDisplayFunc(display);
   glutReshapeFunc(reshape);
   glutMouseFunc(mouse);
   glutMotionFunc(mouseMotion);
   glutKeyboardFunc(keyboard);

   // Set the clear color to black
   glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

   // Smooth shading by default
   glShadeModel(GL_SMOOTH);

   // Enable the depth buffer
   glEnable(GL_DEPTH_TEST);

   // Enable normalization of vectors (so we can do scaling!)
   glEnable(GL_NORMALIZE);

   // Enable back face polygon removal
   glFrontFace(GL_CCW);
   glCullFace(GL_BACK);
   glEnable(GL_CULL_FACE);

   // Set ambient light in the lighting model and enable lighting
   GLfloat ambient[] = { 0.4f, 0.4f, 0.4f, 1.0f };
   glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
   glEnable(GL_LIGHTING);

   //Enable 2D Textures
   glEnable( GL_TEXTURE_2D );

   // Print the keyboard commands
   printf("i - Reset to initial view\n");
   printf("R - Rotate roll 5 degrees clockwise\n");
   printf("r - Rotate roll 5 degrees counter-clockwise\n");
   printf("P - Rotate pitch 5 degrees clockwise\n");
   printf("p - Rotate pitch 5 degrees counter-clockwise\n");
   printf("H - Rotate heading 5 degrees clockwise\n");
   printf("h - Rotate heading 5 degrees counter-clockwise\n");
   printf("V - Faster mouse movement\n");
   printf("v - slower mouse movement\n");
   printf("g - Gouraud shading\n");
   printf("f - Flat shading\n");
   printf("S - Use Shaders (default)\n");
   printf("s - Use fixed function pipeline\n");
   printf("t - Toggle water flow\n");

   CanUseShaders = true;
   glewInit();
	if (glewIsSupported("GL_VERSION_2_0"))
		printf("Can use GLSL as part of OpenGL 2.0\n");
	else 
   {
		printf("OpenGL 2.0 not supported - see if we can use extensions\n");
      if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader) 
	      printf("Can use GLSL with extensions\n");
      else
      { 
         CanUseShaders = false;
         printf("Cannot use GLSL!\n");
      } 
	}

    // Set up shaders
   if (CanUseShaders)
   {
      if (!VertexShader.Create("shaders/phong.vert"))
      {
         printf("Vertex Shader compile failed\n");
         exit(1);
      }
      if (!FragmentShader.Create("shaders/phong.frag"))
      {
         printf("Fragment Shader compile failed\n");
         exit(1);
      }
      ShaderProgram.Create();
      if (!ShaderProgram.AttachShaders(VertexShader.Get(), FragmentShader.Get()))
      {
         printf("Shader program link failed\n");
         exit(1);
      }
      ShaderProgram.Use();
   }

   // Construct scene
   ConstructScene();
   //gluLookAt(0, 1, 3, 0, 1, 0, 0, 1, 0);

   // Set the number of lights used
   int nl = glGetUniformLocation(ShaderProgram.GetProgram(), "numLights");
   glUniform1i(nl, 5);
   //glutIdleFunc(idle);
   glutTimerFunc(1000.0 / FRAME_RATE, timerFunction, 0);
   glutMainLoop();
   return 0;
}
/**
 * Main 
 */
int main(int argc, char** argv)
{
   // Print the keyboard commands
   printf("i - Reset to initial view\n");
   printf("R - Roll    5 degrees clockwise   r - Counter-clockwise\n");
   printf("P - Pitch   5 degrees clockwise   p - Counter-clockwise\n");
   printf("H - Heading 5 degrees clockwise   h - Counter-clockwise\n");
   printf("X - Slide camera right            x - Slide camera left\n");
   printf("Y - Slide camera up               y - Slide camera down\n");
   printf("F - Move camera forward           f - Move camera backwards\n");
   printf("V - Faster mouse movement         v - Slower mouse movement\n");

   // Initialize free GLUT
   glutInit(&argc, argv);
   glutInitContextVersion(3, 2);
   //glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);  // Using this causes LineWidth to error
   glutInitContextProfile(GLUT_CORE_PROFILE);

   // Set up depth buffer and double buffering
   glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);
   glutInitWindowPosition(100, 100);
   glutInitWindowSize(640, 480);

   // Set callback methods
   glutCreateWindow("Phong Shading");
   glutDisplayFunc(display);
   glutReshapeFunc(reshape);
   glutMouseFunc(mouse);
   glutMotionFunc(mouseMotion);
   glutKeyboardFunc(keyboard);

  // Initialize Open 3.2 core profile
   if (gl3wInit()) {
      fprintf(stderr, "gl3wInit: failed to initialize OpenGL\n");
      return -1;
   }
   if (!gl3wIsSupported(3, 2)) {
      fprintf(stderr, "OpenGL 3.2 not supported\n");
      return -1;
   }
   printf("OpenGL %s, GLSL %s\n", glGetString(GL_VERSION), glGetString(GL_SHADING_LANGUAGE_VERSION));

   // Set the clear color to black
   glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

   // Enable the depth buffer
   glEnable(GL_DEPTH_TEST);

   // Enable back face polygon removal
   glFrontFace(GL_CCW);
   glCullFace(GL_BACK);
   glEnable(GL_CULL_FACE);

   // Enable mutlisample anti-aliasing
   glEnable(GL_MULTISAMPLE);

   // Construct scene
   ConstructScene();

   glutMainLoop();
   return 0;
}