Visual Studio 2017配置OpenGL

作者:追风剑情 发布于:2019-6-2 8:58 分类:OpenGL

参见 https://www.cnblogs.com/junjunjun123/p/8609159.html

1、安装nupengl (此包集成了OpenGL、FreeGLUT、GLFW、GLEW)

222.png

2、运行测试代码


  1. #include <windows.h>
  2. #include <GL/gl.h>
  3. #include <GL/glu.h>
  4. #include <GL/glut.h>
  5.  
  6. #include <cstdlib>
  7. #include <cstdio>
  8. #include <cmath>
  9.  
  10. void display(void) {
  11. GLubyte fly[] = {
  12. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  13. 0x03,0x80,0x01,0xC0,0x06,0xC0,0x03,0x60,
  14. 0x04,0x60,0x06,0x20,0x04,0x30,0x0C,0x20,
  15. 0x04,0x18,0x18,0x20,0x04,0x0C,0x30,0x20,
  16.  
  17. 0x04,0x06,0x60,0x20,0x04,0x03,0xC0,0x22,
  18. 0x44,0x01,0x80,0x22,0x44,0x01,0x80,0x22,
  19. 0x44,0x01,0x80,0x22,0x44,0x01,0x80,0x22,
  20. 0x44,0x01,0x80,0x22,0x44,0x01,0x80,0x22,
  21.  
  22. 0x66,0x01,0x80,0x66,0x33,0x01,0x80,0xCC,
  23. 0x19,0x81,0x81,0x98,0x0C,0xC1,0x83,0x30,
  24. 0x07,0xe1,0x87,0xe0,0x03,0x3f,0xfc,0xc0,
  25. 0x03,0x31,0x8c,0xc0,0x03,0x33,0xCC,0xC0,
  26.  
  27. 0x06,0x64,0x26,0x60,0x0c,0xcc,0x33,0x30,
  28. 0x18,0xcc,0x33,0x18,0x10,0xc4,0x23,0x08,
  29. 0x10,0x63,0xc6,0x08,0x10,0x30,0x0c,0x08,
  30. 0x10,0x18,0x18,0x08,0x10,0x00,0x00,0x08,
  31. };
  32.  
  33. GLubyte halftone[] = {
  34. 0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
  35. 0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
  36. 0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
  37. 0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
  38. 0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
  39. 0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
  40. 0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
  41. 0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
  42. 0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
  43. 0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
  44. 0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
  45. 0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
  46. 0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
  47. 0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
  48. 0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
  49. 0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
  50. };
  51.  
  52. glClear(GL_COLOR_BUFFER_BIT);
  53. glColor3f(1.0, 1.0, 1.0);
  54. glRectf(25.0, 25.0, 125.0, 125.0);
  55. glEnable(GL_POLYGON_STIPPLE);
  56. glPolygonStipple(fly);
  57. glRectf(125.0, 25.0, 225.0, 125.0);
  58. glPolygonStipple(halftone);
  59. glRectf(225.0, 25.0, 325.0, 125.0);
  60. glDisable(GL_POLYGON_STIPPLE);
  61. glFlush();
  62. }
  63.  
  64. void init(void) {
  65. glClearColor(0.0, 0.0, 0.0, 0.0);
  66. glShadeModel(GL_FLAT);
  67. }
  68.  
  69. void reshape(int w, int h) {
  70. glViewport(0, 0, (GLsizei)w, (GLsizei)h);
  71. glMatrixMode(GL_PROJECTION);
  72. glLoadIdentity();
  73. gluOrtho2D(0.0, (GLdouble)w, 0.0, (GLdouble)h);
  74. }
  75.  
  76. int main(int argc, char** argv) {
  77. glutInit(&argc, argv);
  78. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  79. glutInitWindowSize(350, 150);
  80. glutCreateWindow(argv[0]);
  81. init();
  82. glutDisplayFunc(display);
  83. glutReshapeFunc(reshape);
  84. glutMainLoop();
  85. return 0;
  86. }


效果

11111.png

标签: OpenGL

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号