Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8417539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:04:42+00:00 2026-06-10T02:04:42+00:00

I am writing CUDA C codes and trying to use OpenGL for the visualization

  • 0

I am writing CUDA C codes and trying to use OpenGL for the visualization of simulation data.

I am using Visual Studio 2010 for development.

I was going through the “CUDA by example” book and tried to reproduce the examples in the book. So in the CUDA OpenGL interoperability section everything did work fine until I began making use of glGenBuffers. Other functions related to buffer objects, like glBindBuffer did not identify during compilation either. I googled a lot about this and there are many suggestions like including “GL/glext.h”, which I all tried.

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. In the VS 2010 Project → properties → linker → input → additional dependencies I added the library files in the following order:

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.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:04:44+00:00Added an answer on June 10, 2026 at 2:04 am

    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. 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. If you use cuda_gl_interop.h you should not use cudagl.h.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty new to CUDA. I use Microsoft Visual Studio 2010 where I don't
I am writing a CUDA kernel in which I'm using the string data type
I am writing host code for a CUDA program, so I am stuck using
I am writing a massively parallel GPU application using CUDA. I have been optimizing
I'm trying the OpenCL-OpenGL interop for textures on my Geforce 330M with CUDA Toolkit
I'm writing a parallel evolutionary algorithm library using C++, MPI and CUDA. I need
I'm writing my own graphics library (yep, its homework:) and use cuda to do
I am currently writing a CUDA application and want to use the boost::program_options library
Writing Classic ASP code in JScript has a lot going for it: more humane
Writing a python program, and I came up with this error while using the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.