![](/img/trans.png)
[英]Compiler errors using boost::asio/windows7/visual studio 2010
[英]Errors while using opengl buffers using visual studio 2010 in windows7
我正在编写CUDA C代码并尝试使用OpenGL来模拟仿真数据。
我正在使用Visual Studio 2010进行开发。
我正在阅读“CUDA by example”一书并尝试重现本书中的例子。 所以在CUDA OpenGL互操作性部分,一切都运行正常,直到我开始使用glGenBuffers
。 与缓冲区对象相关的其他函数(如glBindBuffer
在编译期间也未识别。 我搜索了很多关于这一点的内容,有许多建议,比如包括“GL / glext.h”,我都试过了。
我还想提一下,所有的头文件( glut.h
, glew.h
, glxew.h
和wglew.h
)和lib文件( glut.lib
, glew32.lib
, glew32s.lib
)都存在于Visual Studio中SDK lib
和inc
目录。 在VS 2010项目→属性→链接器→输入→其他依赖项中,我按以下顺序添加了库文件:
cudart.lib glut32.lib glu32.lib glew32.lib glew32s.lib freeglut.lib opengl32.lib
这是我的程序的源代码核心供参考
#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()
}
编译时,我遇到以下错误:
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.
阅读错误消息确实很有帮助。 你的问题是,你盲目地包括一堆标题。 首先,您只需要glew.h
,不要使用glext.h
。 然后,按正确的顺序包含标题也很重要。
这应该工作:
#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>
顺便说一句: cudagl.h
适用于旧的,已弃用的GL交互API。 如果使用cuda_gl_interop.h
,则不应使用cudagl.h
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.