win 10 安装 glew 方法

Posted 齐文宣

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了win 10 安装 glew 方法相关的知识,希望对你有一定的参考价值。

开发环境是 visual studio 2012

1 : 下载 glew 2.0 , 地址 http://glew.sourceforge.net/ 

2 : glew.h 文件copy to  C:\Program Files (x86)\Windows Kits\8.0\Include\um\gl 

3 :  glew.lib  copy to  C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib 

4 : glew32.dll copy to C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin 

 

注意  lib 和 dll 都用32位的 , 因为 VS 在  C:\Program Files (x86)

 

测试程序, 这个能跑起来就说明安装正确 

 

#include <stdio.h>
#include <GL/glew.h>
#include <GL/glut.h>
//#include "ogldev_math_3d.h"

#pragma comment(lib , "glut32.lib")
#pragma comment(lib , "glew32.lib")

struct Vector3f
{
    float x;
    float y;
    float z;

    Vector3f()
    {
    }

    Vector3f(float _x, float _y, float _z)
    {
        x = _x;
        y = _y;
        z = _z;
    }
    
    Vector3f(float f)
    {
        x = y = z = f;
    }

    Vector3f& operator+=(const Vector3f& r)
    {
        x += r.x;
        y += r.y;
        z += r.z;

        return *this;
    }

    Vector3f& operator-=(const Vector3f& r)
    {
        x -= r.x;
        y -= r.y;
        z -= r.z;

        return *this;
    }

    Vector3f& operator*=(float f)
    {
        x *= f;
        y *= f;
        z *= f;

        return *this;
    }

    operator const float*() const
    {
        return &(x);
    }
    
   
    Vector3f Cross(const Vector3f& v) const;

    Vector3f& Normalize();

    void Rotate(float Angle, const Vector3f& Axis);

    void Print() const
    {
        printf("(%.02f, %.02f, %.02f)", x, y, z);
    }
};


GLuint VBO;

static int i = 0;

static void RenderSceneCB()
{

        int j ;
        glClear(GL_COLOR_BUFFER_BIT);

        glEnableVertexAttribArray(0);
        //glBindBuffer(GL_ARRAY_BUFFER, VBO);
        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);

        j = (i++) % 2 ;

        glDrawArrays(GL_POINTS, 0, 1);

        glDrawArrays(GL_POINTS, 0, 2);

        //glDrawArrays(GL_POINTS,j, 1);

        glDisableVertexAttribArray(0);

        glutSwapBuffers();

    
}


static void InitializeGlutCallbacks()
{
    glutDisplayFunc(RenderSceneCB);
    glutIdleFunc(RenderSceneCB);
}

static void CreateVertexBuffer()
{
    Vector3f Vertices[2];
    Vertices[0] = Vector3f(0.0f, 0.0f, 0.0f);

    Vertices[1] = Vector3f(0.2f, 0.2f, 0.0f);

    glPointSize(20.0);
    
     glGenBuffers(1, &VBO);
    glBindBuffer(GL_ARRAY_BUFFER, VBO);
    glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);
}
int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
    glutInitWindowSize(1024, 768);
    glutInitWindowPosition(100, 100);
    glutCreateWindow("Tutorial 02");

    InitializeGlutCallbacks();

    // Must be done after glut is initialized!
    GLenum res = glewInit();
    if (res != GLEW_OK) {
      fprintf(stderr, "Error: ‘%s‘\n", glewGetErrorString(res));
      return 1;
    }

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    CreateVertexBuffer();

    glutMainLoop();

    return 0;
}

 

以上是关于win 10 安装 glew 方法的主要内容,如果未能解决你的问题,请参考以下文章

Win10 VS2015 OpenGL + freeglut + glew + glm 环境配置

win8+sdk8+vs2012+freeglut+glew开发opengl

链接问题 C++、glew 和 SDL

为啥片段着色器没有附加?

在 Windows 10 上安装 Kivy 时,错误消息“致命错误 C1083:无法打开包含文件:'GL/glew.h':没有这样的文件或目录”

0 VS2015 WIN7 配置OPENGL