标签:vbo class err tin net bsp 地址 环境 arrays
开发环境是 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; }
标签:vbo class err tin net bsp 地址 环境 arrays
原文地址:http://www.cnblogs.com/lthxk-yl/p/6867779.html