can any one help me with the following error
GL/glut.h no such file or directory
The things I did are
After installation of MinGW i have added the Path to the path
enviornment variable
Added 'glut.h' to C:\MinGW\Include\GL
Added glut32.dll to C:\Windows\SysWOW64
Added glut32.lib to the project folder
COmpiled with 'g++ -o hello.exe -Wall hello.c glee.lib glut32.lib -lopengl32 -lglu32'
and still the error above persist please help
#include<GL/glut.h>
#include<iostream>
//#include<conio.h>
void render(void);
void keyboard(unsigned char c, int x, int y);
void mouse(int button, int state, int x, int y);
int main(int argc, char** atgv)
{
glutInit(&argc, argv);
glutInitDisplayMode( GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(640, 480);
glutCreateWindow("Sample GLUT Application");
glutDisplayFunc(render);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop();
}
void keyboard(unsigned char c, int x, int y)
{
if(c == 27){
exit(0);
}
}
void mouse(int button, int state, int x, int y)
{
if(button == GLUT_RIGHT_BUTTON )
{
exit(0);
}
}
void render(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glBegin(GL_TRIANGLES);
glColor3f(1, 0, 0);
glVertex2f(-0.5, -0.5);
glColor3f(0, 1, 0);
glVertex2f(0.5, -0.5);
glColor3f(0, 0, 1);
glVertex2f(0.0, 0.5);
glEnd();
glutSwapBuffers();
}
some simple things that can cause problems in my experience (so make sure they are set!:) :
check to see if C:\MinGW\bin is in your path variable if not, add C:\MinGW\bin to your PATH (type %path% in a console window to ensure the path property is applied to the window console session you are using)
put glut32.dll into C:\windows\system32 so it can be located at runtime, or place it in the same directory as the executable you wish to run
Just checked and my minGW has glut32.dll in c:\mingw\bin
and libglut32.a in c:\mingw\lib
and glut.h should be in c:\mingw\include\GL
Apologies for the previous omission.
That should see you alright provided there are no other issues at play.
Let me know if you need more info/help :)
Addendum:
I located this link which whilst old may be of use to you in making the files available to mingw's environment.
On a Debian based systems such as Ubuntu, do
sudo apt-get install libglfw3-dev libgl1-mesa-dev libglu1-mesa-dev
Related
I am making a project in Qt Creator (Linux) where I need to run an x-executable file (output of a C++ program) with the push of a button. Here's the code for it:
void MainWindow::on_pushButton_clicked()
{
QString file = "/home/Test";
QUrl url = QUrl::fromLocalFile(file);
QDesktopServices::openUrl(url);
}
However, when I run the project and use the button to run the above Test file, I get the following error:
gvfs-open: file:///home/Test: error opening location: No application is registered as handling this file
How Should I fix this?
Edit 1: The Test file runs properly when I double click on it, or when using the command ./Test in the terminal.
Edit 2: The source code for the original Test.cpp file:
#include<GL/glut.h>
#include<stdio.h>
void myinit()
{
GLfloat mat_ambient[]={0.3,0.3,0.3,1.0};
GLfloat mat_diffuse[]={0.6,0.6,0.6,1.0};
GLfloat mat_specular[]={0.9,0.9,0.9,1.0};
GLfloat mat_shininess[]={100.0};
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mat_ambient);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mat_diffuse);
glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,mat_shininess);
GLfloat light0_ambient[]={0.5,0.5,0.5,1.0};
GLfloat light0_diffuse[]={1.0,1.0,1.0,1.0};
GLfloat light0_specular[]={1.0,1.0,1.0,1.0};
GLfloat light0_position[]={5.0,5.0,5.0,0.0};
glLightfv(GL_LIGHT0,GL_AMBIENT,light0_ambient);
glLightfv(GL_LIGHT0,GL_DIFFUSE,light0_diffuse);
glLightfv(GL_LIGHT0,GL_SPECULAR,light0_specular);
glLightfv(GL_LIGHT0,GL_POSITION,light0_position);
glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE,light0_ambient);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glEnable(GL_NORMALIZE);
}
void sphere()
{
glPushMatrix();
glutSolidSphere(1.0,100,100);
glPopMatrix();
}
static GLfloat theta[]={0.0,0.0,0.0};
static GLint axis=2.0;
static GLfloat translate[]={0.0,0.0,0.0};
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef( translate[0], translate[1], translate[2]);
glRotatef(theta[0],1.0,0.0,0.0);
glRotatef(theta[1],0.0,1.0,0.0);
glRotatef(theta[2],0.0,0.0,1.0);
sphere();
glFlush();
glutSwapBuffers();
}
void spinsphere()
{
theta[axis]+=10.0;
if(theta[axis]>360.0)
theta[axis]-=360.0;
translate[0] += 0.01; // or any value you see fit
translate[1] += 0.01; // or any value you see fit
translate[2] += 0.01; // or any value you see fit
glutPostRedisplay();
}
void myreshape(int w,int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w<=h)
glOrtho(-2.0,2.0,-2.0*(GLfloat)h/(GLfloat)w,2.0*(GLfloat)h/(GLfloat)w,-10.0,10.0);
else
glOrtho(-2.0*(GLfloat)h/(GLfloat)w,2.0*(GLfloat)h/(GLfloat)w,-2.0,2.0,-10.0,10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("TEST");
glutReshapeFunc(myreshape);
glutDisplayFunc(display);
glutIdleFunc(spinsphere);
myinit();
glutMainLoop();
return 0;
}
According to the documentation:
bool QDesktopServices::openUrl(const QUrl & url)
Opens the given url in the appropriate Web browser for the user's
desktop environment, and returns true if successful; otherwise returns
false.
[...]
The openUrl function tries to open the file via the Web browser (chrome, firefox, etc), but Web browsers can not open an executable. In your case the solution would be to use QProcess:
QString file = "/home/Test";
QProcess::startDetached(file);
I am in the process of checking my OpenGL install works fine, but my example program crashes at execution (with no real error message hint). I am using the unofficial GLSDK (http://glsdk.sourceforge.net/docs/html/index.html) distribution and compiled it under windows 8.
The program (http://www.transmissionzero.co.uk/computing/using-glut-with-mingw/)
#include <glload/gl_3_2_comp.h>
#include <GL/freeglut.h>
void keyboard(unsigned char key, int x, int y);
void display(void);
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutCreateWindow("GLUT Test");
glutKeyboardFunc(&keyboard);
glutDisplayFunc(&display);
glutMainLoop();
return EXIT_SUCCESS;
}
void keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case '\x1B':
exit(EXIT_SUCCESS);
break;
}
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f, 0.0f, 0.0f);
glBegin(GL_POLYGON);
glVertex2f(-0.5f, -0.5f);
glVertex2f( 0.5f, -0.5f);
glVertex2f( 0.5f, 0.5f);
glVertex2f(-0.5f, 0.5f);
glEnd();
glFlush();
}
I know that #include <glload/gl_3_2_comp.h> is the culprit here because if I change this line to #include <GL/gl.h> then the example program runs fine and displays a nice red square on a black background... Alternatively if I remove the contents of the display() function the program runs fine too.
Problem is : I need to use OpenGL 3.x or above API so I can't just include the OS header who is ridiculously outdated (Windows 8).
My Linker settings (in Code::Blocks) :
glloadD
glimgD
glutilD
glmeshD
freeglutD
glu32
opengl32
gdi32
winmm
user32
With include paths :
glsdk\glload\lib
glsdk\glimg\lib
glsdk\glutil\lib
glsdk\glmesh\lib
glsdk\freeglut\lib
And #Defines :
FREEGLUT_STATIC
_LIB
FREEGLUT_LIB_PRAGMAS=0
Based on the GL Load documentation, it looks like you need to explicitly initialize it:
#include <glload/gl_load.h>
...
ogl_LoadFunctions();
where the ogl_LoadFunctions() call needs to be after you set up GLUT.
I just started trying out OpenGL and I'm having a strange issue.
If I compile and execute using g++ test.c -lGL -lGLU -lglut then ./a.out, a sepearate window opens (of the size specified in the code). But instead of having the output of the code in it, it has a screenshot of the screen inside it (of the portion of the screen it overlaps).
This is definitely not something to do with the code, since it's running fine on my friend's computer. But I need to fix it on my PC.
I'm on Linux Mint 15 64bit (HP DV6 6121tx).
So I'm not able to proceed further. Here's my code:
#include <GL/gl.h>
#include <GL/glut.h>
#define drawOneLine(x1,y1,x2,y2) glBegin(GL_LINES); glVertex2f ((x1),(y1)); glVertex2f ((x2),(y2)); glEnd();
void init()
{
glClearColor(1.0,1.0,1.0,0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D (-600,600,-400,400);
glClear(GL_COLOR_BUFFER_BIT);
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(0,0);
glutInitWindowSize(1200,800);
glutCreateWindow("ABCD");
init();
glutMainLoop();
return 0;
}
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
^^^^^^^^^^^
You've asked for a single-buffered window so you'll have to glFlush()/glFinish() to force queued output to the screen.
Add a glFinish() to the end of init().
So I've been following a tutorial and when I tried to compile the below code:
#include <glut.h>
#include <iostream>
void render(void);
void keyboard(unsigned char c, int x, int y);
void mouse(int button, int state, int x, int y);
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(640, 480);
glutCreateWindow("Test GLUT App");
glutDisplayFunc(render); // render
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop(); // initialization finished. start rendering
}
void render(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3f(0.5, 0.2, 0.9);
glVertex2f(-0.5, -0.5);
glColor3f(0.1, 0.2, 0.5);
glVertex2f(0.0, -0.5);
glColor3f(0.3, 0.9, 0.7);
glVertex2f(0.0, 0.5);
glEnd();
glutSwapBuffers();
}
void keyboard(unsigned char c, int x, int y)
{
if(c == 27)
{
exit(0);
}
}
void mouse(int button, int state, int x, int y)
{
if(button == GLUT_RIGHT_BUTTON)
{
exit(0);
}
}
I get 3 errors out of nowhere:
Error 1 error C2381: 'exit' : redefinition; __declspec(noreturn) differs c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdlib.h 353
Error 2 error C3861: 'exit': identifier not found ....main.cpp 45
Error 3 error C3861: 'exit': identifier not found ....main.cpp 53
Does anyone see why this error appears? Im using VS2010.
You need to #include <cstdlib>.
edit:
You are probably following a very known tutorial that provides a header file for you.
This will help you then GLUT exit redefinition error
If your Visual Studio throws a build error saying IntelliSense did not identify 'exit' then you must include process.h
Try adding using namespace std to the top. I'm not sure if this will fix it but i had a similar error earlier and that fixed it. good luck.
u need to declare header simple as work , works in my comp
#include <stdlib.h>
#include <cstdlib>
#include <glut.h>
#include <iostream>
I had OpenGL project for finding a convex hull written in Windows.
Now i'm using Ubuntu 10.10 and i tried to port the code (It's C++ code) and run it.
I saw that, it should be compiled this way :
g++ convex.cpp -lm -lglut -lGLU -o convex_hull_project
It compiles the file, but when i run the file ./convex_hull_project it starts the program, shows the title but there is nothing - it only docks for the bottom task line and when i click it - nothing shows. There is no window with the program.
Any idea ?
Here's the code that uses OpenGL stuff :
int main(int argc, char* argv[]) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH); // color, buffer
glutInitWindowPosition(100,100);
glutInitWindowSize(window_size_width,window_size_height);
glutCreateWindow("Convex hull");
glutDisplayFunc(renderScene);
glutMouseFunc(mouse);
glutMainLoop();
return 0;
}
void renderScene(void) {
// clear framebuffer
glClearColor(0.f,0.f,0.f,0.f);
glClear(GL_COLOR_BUFFER_BIT);
// set-up matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,window_size_width,window_size_height,0,-1,1);
glViewport(0,0,window_size_width,window_size_height);
//drawing ...
}
And includes are :
#include<GL/glut.h>
#include<GL/glu.h>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
You have to call glutCreateWindow before you set windows's properties. Your code, fixed (I've replaced width and height constants with 300 just to get it to compile and commented out mouse handler registration):
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <GL/glut.h>
#include <GL/glu.h>
void renderScene(void) {
// clear framebuffer
glClearColor (0.f,0.f,0.f,0.f);
glClear (GL_COLOR_BUFFER_BIT);
// set-up matrix
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (0, 300, 300, 0,-1,1);
glViewport (0,0,300, 300);
//drawing ...
}
int main(int argc, char* argv[])
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH); // color, buffer
glutCreateWindow ("Convex hull");
glutInitWindowPosition (100, 100);
glutInitWindowSize (300, 300);
glutDisplayFunc (renderScene);
//glutMouseFunc (mouse);
glutMainLoop ();
}