PDA

View Full Version : Problem with code!



12-28-2005, 10:15 AM
Anyone can tell me why this code don't compile!

Onde person gave me this code to compile on my computer to now if it is well installed.

only one more thing why i don't have glut.h????


#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>

#define DimWX 400 /*Dimensoes da janela */
#define DimWY 200

int point_x= DimWX/2, point_y=DimWY/2;

void init (void);
void display (void);
void keyboard (unsigned char key, int x, int y);

int main(int argc, char * argv[]) {
glutInit(&amp;argc, argv);

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

glutInitWindowSize(DimWX, DimWY);
glutInitWindowPosition (100,100);

glutCreateWindow("Mover o ponto com n, s, e, w");

init();

glutDisplayFunc(display);

glutKeyboardFunc(keyboard);

glutMainLoop();

return 0;
}

void init(void) {
glClearColor(1.0, 1.0, 1.0, 1.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0, DimWX, 0, DimWY);
}

void display (void) {
glClear(GL_COLOR_BUFFER_BIT);

glColor3f(0.0, 0.0, 0.0);

glBegin(GL_POINTS);

glVertex2i(point_x, point_y);

glEnd();
glFlush();
}

void keyboard (unsigned char key, int x, int y) {
switch (key) {
case 'q':
exit(0);
break;
case 'n':
point_y += 1;
break;
case 's':
point_y -= 1;
break;
case 'e':
point_x -= 1;
break;
case 'w':
point_x +=1;
break;
}

printf("px=%d py=%d, x=%d y=%d \n", point_x, point_y, x, y);
glutPostRedisplay();
}PS: sory my lasy english

GMan
12-28-2005, 10:46 AM
I just tested that code and it compiled correctly for me.

If you don't have glut you can get it here:
http://www.nigels.com/glt/devpak/

what compiler are you using?

If you are using glut then download the GLUT.3.7.6+ package. Then to compile that code the easiest thing to do is go to FILE->NEW->PROJECT then click the MultiMedia tab and select glut, which should appear if you installed it properly. Also, once you do that go to PROJECT->PROJECT OPTIONS then click the parameters tab and make sure that the following is entered in the linker box "-lglut32 -lglu32 -lopengl32 -lwinmm -lgdi32".

If your not using Dev-C++ then state which compiler you're using and someone can help you, although it should be similar to my explanation above.

12-28-2005, 03:57 PM
I am in mandriva linux 2006 this that u said is for windows... :(

I am using gcc to compile this... it's a problem of libraries... =(

If anyone knows how can i install glut in linux, please help me...

12-28-2005, 04:18 PM
Sory about last post....... :( :( :( :( :( :(

cc -o igraph igraph.c -lglut32 -lm

/home/jorge/tmp/cc0jjEHK.o: In function `main':
igraph.c:(.text+0x27): undefined reference to `glutInit'
igraph.c:(.text+0x34): undefined reference to `glutInitDisplayMode'
igraph.c:(.text+0x49): undefined reference to `glutInitWindowSize'
igraph.c:(.text+0x58): undefined reference to `glutInitWindowPosition'
igraph.c:(.text+0x68): undefined reference to `glutCreateWindow'
igraph.c:(.text+0x7d): undefined reference to `glutDisplayFunc'
igraph.c:(.text+0x8d): undefined reference to `glutKeyboardFunc'
igraph.c:(.text+0x95): undefined reference to `glutMainLoop'
/home/jorge/tmp/cc0jjEHK.o: In function `init':
igraph.c:(.text+0xbf): undefined reference to `glClearColor'
igraph.c:(.text+0xcf): undefined reference to `glMatrixMode'
igraph.c:(.text+0x107): undefined reference to `gluOrtho2D'
/home/jorge/tmp/cc0jjEHK.o: In function `display':
igraph.c:(.text+0x11f): undefined reference to `glClear'
igraph.c:(.text+0x13c): undefined reference to `glColor3f'
igraph.c:(.text+0x149): undefined reference to `glBegin'
igraph.c:(.text+0x161): undefined reference to `glVertex2i'
igraph.c:(.text+0x169): undefined reference to `glEnd'
igraph.c:(.text+0x16e): undefined reference to `glFlush'
collect2: ld returned 1 exit status

adz21c
12-29-2005, 05:18 PM
In Mandriva Control Center or Smart Package manager which ever you prefer install libMesaglut3 and the devel library for it. In my experience this still didn't work for me (I honestly have no idea why, it installs the correct library and header files yet still fails for me on Mandriva 2006 x64).

I did however find anything to do with glut started working as soon as I compiled and installed freeglut.

songho
12-29-2005, 08:01 PM
The linker option for linux platform should be -lglut -lGL -GLU.

glut32 is for MS windows specific.
==song==

adz21c
12-30-2005, 07:47 AM
I thought it's "-lGLU" not "-GLU". In any case, I have tried compiling his code myself it just doesn't seem to want to work (that includes compiling against thac's xorg that comes with Mesa 6.4.1 instead of Mandriva's 5.0.2).
Without providing "-lglut -lGL -lGLU" you get same problem as mentioned here for obvious reasons, however when you provide them it is unable to find any of the libraries ("/usr/bin/ld: cannot find -lGL"). I honestly don't understand it.

I personally gave in and started messing with OpenGL in Qt instead and pretty much everything I do works fine there. The coding provided converted to Qt would work no problem at all. The only other option I would have had would be to continue using freeglut.

songho
01-02-2006, 08:54 AM
adz21c,
Thanks for pointing out the typo. Yes, it should be -lGLU for linking glu library. It is my bad.