私は 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 SDKlib
と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.