VS2010下,identifier "cudaGLSetGLDevice" is undefined

afunlee 2011-02-26 10:55:01
#include <cuda.h>
#include <gl/glut.h>

GLuint positionsVBO;
struct cudaGraphicsResource * positionsVBO_CUDA;

void display()
{
//Map buffer object for writing from CUDA
float4* positions;
cudaGraphicsMapResources(1,&positionsVBO_CUDA,0);
size_t num_bytes;
cudaGraphicsResourceGetMappedPointer((void**)&positions,&num_bytes,positionsVBO_CUDA);
//Execute kernel
dim3 dimBlock(16,16,1);
dim3 dimGrid(width/dimBlock.x,height/blockDim.y,1);
createVertices<<<dimGrid,dimBlock>>>(positions,time,width,height);
//Unmap buffer object
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glBindBuffer(GL_ARRAY_BUFFER,positionsVBO);
glVertexPointer(4,GL_FLOAT,0,0);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_POINTS,0,width*height);
glDisableClientState(GL_VERTEX_ARRAY);
//Swap buffers
glutSwapBuffers();
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
//Explicitly set device
cudaGLSetGLDevice(0);
//Initialize OpenGL and GLUT
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(100, 100);
glutInitWindowSize(400, 400);
glutCreateWindow("OpenGL");
glutDisplayFunc(display);
//Create buffer object and register it with CUDA
glGenBuffers(1,positionsVBO);
glBindBuffer(GL_ARRAY_BUFFER,&vbo);
unsigned int size=width*height*4*sizeof(float);
glBufferData(GL_ARRAY_BUFFER,size,0,GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER,0);
cudaGraphisGLRegisterBuffer(&positionsVBO_CUDA,positionsVBO,cudaGraphicsMapFlagsWriteDiscard);
//Launch rendering loop
glutMainLoop();
}


void deleteVBO()
{
cudaGraphicsUnregisterResource(positionsVBO_CUDA);
glDeleteBuffers(1,&positionsVBO);
}

__global__ void createVertices(float4* positions,float time,unsigned int width,unsigned int height)
{
unsigned int x=blockIdx.x*blockDim.x+threadIdx.x;
unsigned int y=blockIdx.y*blockDim.y+threadIdx.y;
//Calculate uv coordinates
float u=x/(float)width;
float v=y/(float)height;
u=u*0.2f-1.0f;
v=v*0.2f-1.0f;
//Calculate simple sine wave pattern
float freq=4.0f;
float w=sinf(u*freq+time)*cosf(v*freq+time)*0.5f;
//Write possitions
positions[y*width+x]=make_float4(u,w,v,1.0f);
}


这个代码咱是仿照别人打,然后出现了各种各样的错误(不只咱做标题的那个错误...)求高手运行后,给个答复谢啦~~~
...全文
249 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
windog18 2011-02-27
  • 打赏
  • 举报
回复
要包含CUDA的头文件
#ifndef __CUDA_RUNTIME_H__
#include <cuda_runtime.h>
#endif
#ifndef _CUTIL_INLINE_H_
#include <cutil_inline.h>
#endif
#ifndef _CUTIL_GL_INLINE_H_
#include <cutil_gl_inline.h>
#endif
#ifndef __CUDA_GL_INTEROP_H__
#include <cuda_gl_interop.h>
#endif
#ifndef __VECTOR_TYPES_H__
#include <vector_types.h>
#endif
#ifndef _RENDERCHECK_GL_H_
#include <rendercheck_gl.h>
#endif
afunlee 2011-02-27
  • 打赏
  • 举报
回复
哎~还是有点问题,估计是我装那个CudaVs2010的时候出了问题....

581

社区成员

发帖
与我相关
我的任务
社区描述
CUDA™是一种由NVIDIA推出的通用并行计算架构,该架构使GPU能够解决复杂的计算问题。 它包含了CUDA指令集架构(ISA)以及GPU内部的并行计算引擎。
社区管理员
  • CUDA编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧