简体   繁体   English

在windows7中使用visual studio 2010使用opengl缓冲区时出错

[英]Errors while using opengl buffers using visual studio 2010 in windows7

I am writing CUDA C codes and trying to use OpenGL for the visualization of simulation data. 我正在编写CUDA C代码并尝试使用OpenGL来模拟仿真数据。

I am using Visual Studio 2010 for development. 我正在使用Visual Studio 2010进行开发。

I was going through the "CUDA by example" book and tried to reproduce the examples in the book. 我正在阅读“CUDA by example”一书并尝试重现本书中的例子。 So in the CUDA OpenGL interoperability section everything did work fine until I began making use of glGenBuffers . 所以在CUDA OpenGL互操作性部分,一切都运行正常,直到我开始使用glGenBuffers Other functions related to buffer objects, like glBindBuffer did not identify during compilation either. 与缓冲区对象相关的其他函数(如glBindBuffer在编译期间也未识别。 I googled a lot about this and there are many suggestions like including "GL/glext.h", which I all tried. 我搜索了很多关于这一点的内容,有许多建议,比如包括“GL / glext.h”,我都试过了。

I would also like to mention that all of the headers ( glut.h , glew.h , glxew.h and wglew.h ) and lib files ( glut.lib , glew32.lib , glew32s.lib ) are present in the Visual Studio SDK lib and inc directories. 我还想提一下,所有的头文件( glut.hglew.hglxew.hwglew.h )和lib文件( glut.libglew32.libglew32s.lib )都存在于Visual Studio中SDK libinc目录。 In the VS 2010 Project → properties → linker → input → additional dependencies I added the library files in the following order: 在VS 2010项目→属性→链接器→输入→其他依赖项中,我按以下顺序添加了库文件:

cudart.lib glut32.lib glu32.lib glew32.lib glew32s.lib freeglut.lib opengl32.lib cudart.lib glut32.lib glu32.lib glew32.lib glew32s.lib freeglut.lib opengl32.lib

Here's my program's source core for reference 这是我的程序的源代码核心供参考

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glut.h>
#include <GL/freeglut.h>
#include <GL/glew.h>
#include <GL/glext.h>
#include <cuda.h>
#include <cuda_runtime.h>
#include <cutil.h>
#include <cudagl.h>
#include <cuda_gl_interop.h>

#define DIM 512;

GLuint bufferObj;
cudaGraphicsResource *resource;


    void display (void) 
    { 
    glClearColor(1.0f, 0.0f, 0.0f, 1.0f); 
    glClear(GL_COLOR_BUFFER_BIT); 
    glLoadIdentity(); 
    glFlush(); 
    } 
    void reshape (int width, int height) 
    { 
    glViewport(0, 0, (GLsizei)width, (GLsizei)height); 
    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 
    gluPerspective(60, (GLfloat)width / (GLfloat)height, 1.0, 100.0); 
    glMatrixMode(GL_MODELVIEW); 
    } 


    int main(int argc,char **argv)
    {
    cudaDeviceProp prop;
    int dev;

    memset(&prop,0,sizeof(cudaDeviceProp));
    prop.major = 1;
    prop.minor = 0;

    cudaChooseDevice(&dev,&prop);
    cudaGLSetGLDevice(dev);
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
    glutInitWindowSize(512, 512);
    glutInitWindowPosition (100, 100); 
    glutCreateWindow("Bitmap");
    glutDisplayFunc(display); 
    glutReshapeFunc(reshape); 
    glutMainLoop(); 
    glGenBuffers(1,&bufferObj);
    //glBindBuffer()
    }

When compiling, I'm presented with the following errors: 编译时,我遇到以下错误:

1> C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.2\C\common\inc\GL/glut.h(574) : see previous definition of 'GLUT_GAME_MODE_DISPLAY_CHANGED'
1>C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.2\C\common\inc\GL/glew.h(84): fatal error C1189: #error : gl.h included before glew.h
1> 
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizatio ns\CUDA 4.2.targets(361,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\bin\nvcc.exe" -gencode=arch=compute_10,code=\"sm_10,compute_10\" --use-local-env --cl-version 2008 -ccbin "c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin" -I"C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.2\C\common\inc" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\include" -G --keep-dir "Debug" -maxrregcount=0 --machine 32 --compile -g -Xcompiler "/EHsc /nologo /Od /Zi /MDd " -o "Debug\OPENGL_PRAC_1.cu.obj" "C:\Users\umdutta\Desktop\SANKHA_ALL_MATERIALS\PRO GRAMMING_FOLDER\CUDA_OPENGL_C\2_PRACTICE_PROG_FOLD ER_(OPENGL_PRAC)\PROJ_NUM_1_OPENGL\PROJ_NUM_1_OPEN GL\OPENGL_PRAC_1.cu"" exited with code 2.
1>
1>Build FAILED.

It really helps to read the error messages. 阅读错误消息确实很有帮助。 Your problem is, that you mindlessly include a bunch of headers. 你的问题是,你盲目地包括一堆标题。 First, you need only glew.h , and don't use glext.h . 首先,您只需要glew.h ,不要使用glext.h Then it's also important to include the headers in the right order. 然后,按正确的顺序包含标题也很重要。

This should work: 这应该工作:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* GLEW covers everything OpenGL.
   When you use GLEW you do not need any other OpenGL header */
#include <GL/glew.h>

/* GLUT is not part of OpenGL. Either use glut.h or freeglut.h – not both. */
#include <GL/glut.h>

#include <cuda.h>
#include <cuda_runtime.h>
#include <cutil.h>
#include <cuda_gl_interop.h>

BTW: cudagl.h is for the old, deprecated GL interaction API. 顺便说一句: cudagl.h适用于旧的,已弃用的GL交互API。 If you use cuda_gl_interop.h you should not use cudagl.h . 如果使用cuda_gl_interop.h ,则不应使用cudagl.h

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM