Reputation: 2508
I am using Ubuntu 12.04 and I have installed OpenGL4.
I also have a CUDA-enable NVIDIA graphics card. Note that, I have been doing parallel computation with CUDA on my PC and that works.
[eeuser@roadrunner sample_opengl]$ glxinfo | grep gl
server glx vendor string: NVIDIA Corporation
server glx version string: 1.4
server glx extensions:
client glx vendor string: NVIDIA Corporation
client glx version string: 1.4
client glx extensions:
GL_ARB_texture_query_lod, GL_ARB_texture_rectangle, GL_ARB_texture_rg,
GL_NV_texture_multisample, GL_NV_texture_rectangle, GL_NV_texture_shader,
I cannot get a simple program to work. Can anyone give a sample program that can work on my PC
Here is the code I am using:
#include <GL/glew.h> // include GLEW and new version of GL on Windows
#include <GLFW/glfw3.h> // GLFW helper library
#include <stdio.h>
int main () {
// start GL context and O/S window using the GLFW helper library
if (!glfwInit ()) {
fprintf (stderr, "ERROR: could not start GLFW3\n");
return 1;
}
// uncomment these lines if on Apple OS X
/*glfwWindowHint (GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint (GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint (GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);*/
GLFWwindow* window = glfwCreateWindow (640, 480, "Hello Triangle", NULL, NULL);
if (!window) {
fprintf (stderr, "ERROR: could not open window with GLFW3\n");
glfwTerminate();
return 1;
}
glfwMakeContextCurrent (window);
// start GLEW extension handler
glewExperimental = GL_TRUE;
glewInit ();
// get version info
const GLubyte* renderer = glGetString (GL_RENDERER); // get renderer string
const GLubyte* version = glGetString (GL_VERSION); // version as a string
printf ("Renderer: %s\n", renderer);
printf ("OpenGL version supported %s\n", version);
// tell GL to only draw onto a pixel if the shape is closer to the viewer
glEnable (GL_DEPTH_TEST); // enable depth-testing
glDepthFunc (GL_LESS); // depth-testing interprets a smaller value as "closer"
/* OTHER STUFF GOES HERE NEXT */
// close GL context and any other GLFW resources
glfwTerminate();
return 0;
}
I tried compiling with -
g++ main2.cpp -lglut -lGL -lGLEW -lGLU
I get an error :
main2.cpp:2:47: fatal error: GLFW/glfw3.h: No such file or directory
compilation terminated.
I am now wondering what is this GLFW? More precisely how do I install it? Following @eapert I installed libglfw as -
sudo apt-get install libglfw-dev
Still get the following errors
main2.cpp: In function ‘int main()’:
main2.cpp:18:2: error: ‘GLFWwindow’ was not declared in this scope
main2.cpp:18:14: error: ‘window’ was not declared in this scope
main2.cpp:18:79: error: ‘glfwCreateWindow’ was not declared in this scope
main2.cpp:24:32: error: ‘glfwMakeContextCurrent’ was not declared in this scope
Upvotes: 2
Views: 4522
Reputation: 1413
Install the "dev" package for GLFW: sudo apt-get install libglfw3-dev
Warning: the version you get from the package manager may be out of date.
You can follow the instructions here or here.
Upvotes: 3
Reputation: 162317
I tried compiling with -
g++ main2.cpp -lglut -lGL -lGLEW -lGLU
Why are you linking GLUT when you want to use GLFW? Also you don't need GLU for your program. Try this:
g++ main2.cpp -lGL -lGLEW -lglfw
Upvotes: 2
Reputation: 15703
WARNING: The question was changed quite significantly since this answer was made
"I tried a few tutorials but I cannot get a simple program to work" I assume, given what you said earlier, your CUDA programs work on Windows, just not on Ubuntu?
1) Try installing a newer Ubuntu version first (if you have the option on that PC). 12.04 is a bit old and you probably shouldn't be using it if you don't have a good reason to (i.e. it's a company PC and you would violate upgrade policy, something along those lines)
2) Try installing the proprietary NVIDIA drivers for your card (this should also give you the NVIDIA OpenGL implementation); You probably have mesa
installed. I suppose current mesa
version have at least some GPGPU support, but I'm not sure if they support CUDA (if you aren't particularly fond of CUDA you can also try OpenCL, you might have better chances with that. Although there's still a good chance you'll need the proprietary NVIDIA drivers).
GLFW is a helper library for creating windows, setting up OpenGL in them and provides access to input functions etc. It's similar to GLUT - which you seem to be familiar with - in that regard, but a much more modern alternative. You'll of course need to install it to use it. You should be able to install it through Ubuntus package manager as per usual, try apt-cache search glfw
which should help you find the exact package name. If there are multiple "lib" versions, install the one ending in -dev
.
Upvotes: 0