zoukankan      html  css  js  c++  java
  • 在VS2017中安装OpenGL

    由于VS2017支持直接下载有关openGL的库文件,因此给我们带来了很多方便之处,不需要单独下载了。

    1.打开VS2017,并新建一个C++控制台项目

    2.然后点击 项目—管理Nuget程序包,

    点击浏览在搜索栏输入NupenGL,

    然后、安装(如果有两个就安装两个)。

    3.最后就是测试了,我找了一些相关的源代码试验了一下,果然没什么问题。

     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 }  

    结果如下

     

    果然安装成功。

    但是笔者也遇到了一些比较苦恼的事,就是每次将这个项目关闭了以后,再新建另一个项目,这时要想使用openGL就需要重新下载,希望有知道如何解决的读者给我留言哈!!

  • 相关阅读:
    2. Python语言基本语法
    wx.onMenuShareTimeline使用注意事项
    a different object with the same identifier value was already associated with the session:
    linux 下压缩大批量文件
    mysql sleep进程过多,应用级配置
    一次心惊肉跳的服务器误删文件的恢复过程
    分享一个css3写的气泡对话框,适合于即时通讯和留言本的动态内容
    一次Mysql 死锁事故
    adb server is out of date. killing...
    Redis 数据序列化方法 serialize, msgpack, json, hprose 比较
  • 原文地址:https://www.cnblogs.com/junjunjun123/p/8609159.html
Copyright © 2011-2022 走看看