Problemas com OpenGL no linux [RESOLVIDO]

1. Problemas com OpenGL no linux [RESOLVIDO]

John
john.henrique

(usa Ubuntu)

Enviado em 22/08/2009 - 12:14h

Olá.
Faz algum tempo que venho tentando usar o opengl no ubuntu 9.04, já instalei o mesa, depois mudei pro glut. E com nenhum deles consegui fazer com que o codeblocks reconheça as bibliotecas, e suas respectivas funções.
Acredito que ele está procurando elas em um lugar diferente de onde elas estão realmente instaladas.
Mas não faço a menor idéia de onde elas estejam ou como configurar o codeblocks para buscá-las.
Aguardo respostas...



  


2. Re: Problemas com OpenGL no linux [RESOLVIDO]

Alex Fernando Ferreira
staltux

(usa Slackware)

Enviado em 22/08/2009 - 19:20h

aqui eu uso normal...só pra constar verifique uma coisa:

Project -> Build Optons ->Linker Settings -> Linker Libraries:

da um add e coloca as seguintes libs

glut
GL
GLU
Xxf86vm

aqui está assim e esta funcionando...se não der posta ai o codigo do erro ok
outra coisa...não esquece do
#include <GL/glut.h>

conseguindo ou não avisa...


3. Re: Problemas com OpenGL no linux [RESOLVIDO]

John
john.henrique

(usa Ubuntu)

Enviado em 22/08/2009 - 20:55h

acredito de tanto mexer pioreis as coisas, antes o código exemplo do codeblocks compilava e rodava mostrando um cubo, mas agora aparece o seguinte:
main: X server has no OpenGL GLX extension

será que exclui algo que não devia...?!
tentei adicionar lá as lib, mas tbm não surtiu efeito...

O código-exemplo do codeblocks é o seguinte:
/* A simple program to show how to set up an X window for OpenGL rendering.
* X86 compilation: gcc -o -L/usr/X11/lib main main.c -lGL -lX11
* X64 compilation: gcc -o -L/usr/X11/lib64 main main.c -lGL -lX11
*/
#include <stdio.h>
#include <stdlib.h>

#include <GL/glx.h> /* this includes the necessary X headers */
#include <GL/gl.h>

#include <X11/X.h> /* X11 constant (e.g. TrueColor) */
#include <X11/keysym.h>

static int snglBuf[] = {GLX_RGBA, GLX_DEPTH_SIZE, 16, None};
static int dblBuf[] = {GLX_RGBA, GLX_DEPTH_SIZE, 16, GLX_DOUBLEBUFFER, None};

Display *dpy;
Window win;
GLfloat xAngle = 42.0, yAngle = 82.0, zAngle = 112.0;
GLboolean doubleBuffer = GL_TRUE;

void fatalError(char *message)
{
fprintf(stderr, "main: %s\n", message);
exit(1);
}

void redraw(void)
{
static GLboolean displayListInited = GL_FALSE;

if (displayListInited)
{
/* if display list already exists, just execute it */
glCallList(1);
}
else
{
/* otherwise compile and execute to create the display list */
glNewList(1, GL_COMPILE_AND_EXECUTE);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

/* front face */
glBegin(GL_QUADS);
glColor3f(0.0, 0.7, 0.1); /* green */
glVertex3f(-1.0, 1.0, 1.0);
glVertex3f(1.0, 1.0, 1.0);
glVertex3f(1.0, -1.0, 1.0);
glVertex3f(-1.0, -1.0, 1.0);

/* back face */
glColor3f(0.9, 1.0, 0.0); /* yellow */
glVertex3f(-1.0, 1.0, -1.0);
glVertex3f(1.0, 1.0, -1.0);
glVertex3f(1.0, -1.0, -1.0);
glVertex3f(-1.0, -1.0, -1.0);

/* top side face */
glColor3f(0.2, 0.2, 1.0); /* blue */
glVertex3f(-1.0, 1.0, 1.0);
glVertex3f(1.0, 1.0, 1.0);
glVertex3f(1.0, 1.0, -1.0);
glVertex3f(-1.0, 1.0, -1.0);

/* bottom side face */
glColor3f(0.7, 0.0, 0.1); /* red */
glVertex3f(-1.0, -1.0, 1.0);
glVertex3f(1.0, -1.0, 1.0);
glVertex3f(1.0, -1.0, -1.0);
glVertex3f(-1.0, -1.0, -1.0);
glEnd();
glEndList();
displayListInited = GL_TRUE;
}
if (doubleBuffer)
glXSwapBuffers(dpy, win);/* buffer swap does implicit glFlush */
else
glFlush(); /* explicit flush for single buffered case */
}

int main(int argc, char **argv)
{
XVisualInfo *vi;
Colormap cmap;
XSetWindowAttributes swa;
GLXContext cx;
XEvent event;
GLboolean needRedraw = GL_FALSE, recalcModelView = GL_TRUE;
int dummy;

/*** (1) open a connection to the X server ***/

dpy = XOpenDisplay(NULL);
if (dpy == NULL)
fatalError("could not open display");

/*** (2) make sure OpenGL's GLX extension supported ***/

if(!glXQueryExtension(dpy, &dummy, &dummy))
fatalError("X server has no OpenGL GLX extension");

/*** (3) find an appropriate visual ***/

/* find an OpenGL-capable RGB visual with depth buffer */
vi = glXChooseVisual(dpy, DefaultScreen(dpy), dblBuf);
if (vi == NULL)
{
vi = glXChooseVisual(dpy, DefaultScreen(dpy), snglBuf);
if (vi == NULL) fatalError("no RGB visual with depth buffer");
doubleBuffer = GL_FALSE;
}
if(vi->class != TrueColor)
fatalError("TrueColor visual required for this program");

/*** (4) create an OpenGL rendering context ***/

/* create an OpenGL rendering context */
cx = glXCreateContext(dpy, vi, /* no shared dlists */ None,
/* direct rendering if possible */ GL_TRUE);
if (cx == NULL)
fatalError("could not create rendering context");

/*** (5) create an X window with the selected visual ***/

/* create an X colormap since probably not using default visual */
cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone);
swa.colormap = cmap;
swa.border_pixel = 0;
swa.event_mask = KeyPressMask | ExposureMask
| ButtonPressMask | StructureNotifyMask;
win = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0,
300, 300, 0, vi->depth, InputOutput, vi->visual,
CWBorderPixel | CWColormap | CWEventMask, &swa);
XSetStandardProperties(dpy, win, "main", "main", None,
argv, argc, NULL);

/*** (6) bind the rendering context to the window ***/

glXMakeCurrent(dpy, win, cx);

/*** (7) request the X window to be displayed on the screen ***/

XMapWindow(dpy, win);

/*** (8) configure the OpenGL context for rendering ***/

glEnable(GL_DEPTH_TEST); /* enable depth buffering */
glDepthFunc(GL_LESS); /* pedantic, GL_LESS is the default */
glClearDepth(1.0); /* pedantic, 1.0 is the default */

/* frame buffer clears should be to black */
glClearColor(0.0, 0.0, 0.0, 0.0);

/* set up projection transform */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 10.0);
/* establish initial viewport */
/* pedantic, full window size is default viewport */
glViewport(0, 0, 300, 300);

printf( "Press left mouse button to rotate around X axis\n" );
printf( "Press middle mouse button to rotate around Y axis\n" );
printf( "Press right mouse button to rotate around Z axis\n" );
printf( "Press ESC to quit the application\n" );

/*** (9) dispatch X events ***/

while (1)
{
do
{
XNextEvent(dpy, &event);
switch (event.type)
{
case KeyPress:
{
KeySym keysym;
XKeyEvent *kevent;
char buffer[1];
/* It is necessary to convert the keycode to a
* keysym before checking if it is an escape */
kevent = (XKeyEvent *) &event;
if ( (XLookupString((XKeyEvent *)&event,buffer,1,&keysym,NULL) == 1)
&& (keysym == (KeySym)XK_Escape) )
exit(0);
break;
}
case ButtonPress:
recalcModelView = GL_TRUE;
switch (event.xbutton.button)
{
case 1: xAngle += 10.0;
break;
case 2: yAngle += 10.0;
break;
case 3: zAngle += 10.0;
break;
}
break;
case ConfigureNotify:
glViewport(0, 0, event.xconfigure.width,
event.xconfigure.height);
/* fall through... */
case Expose:
needRedraw = GL_TRUE;
break;
}
} while(XPending(dpy)); /* loop to compress events */

if (recalcModelView)
{
glMatrixMode(GL_MODELVIEW);

/* reset modelview matrix to the identity matrix */
glLoadIdentity();

/* move the camera back three units */
glTranslatef(0.0, 0.0, -3.0);

/* rotate by X, Y, and Z angles */
glRotatef(xAngle, 0.1, 0.0, 0.0);
glRotatef(yAngle, 0.0, 0.1, 0.0);
glRotatef(zAngle, 0.0, 0.0, 1.0);

recalcModelView = GL_FALSE;
needRedraw = GL_TRUE;
}
if (needRedraw)
{
redraw();
needRedraw = GL_FALSE;
}
}

return 0;
}

O que estava querendo testar, e estava dando as funções como não declaradas antes é:

#include <GL/gl.h>
#include <GL/glut.h>
void main( int argc, char** argv )
{
int mode = GLUT_DOUBLE | GLUT_RGB;
glutInitDisplayMode( mode );
glutInitWindowSize(400,350);
glutInitWindowPosition(10,10);
glutCreateWindow( argv[0] );
init();
glutDisplayFunc( display );
glutReshapeFunc( resize );
glutKeyboardFunc( key );
glutIdleFunc( idle );
glutMainLoop();
}

Que copiei do REDBOOK do opengl...


4. Re: Problemas com OpenGL no linux [RESOLVIDO]

Alex Fernando Ferreira
staltux

(usa Slackware)

Enviado em 22/08/2009 - 21:35h

o problema parece ser o seu X e nao o seu codigo...da uma olhada no /etc/X11/xorg.conf

olha a parte:

Section "Module"

e insira(se ainda nao tiver) a linha:

Load "glx"

e reinicia o X

outra coisa:

vc já instalou o driver proprietario da sua placa de video ?geralmente o instalador do drive ja configura a "extenção GL" pra vc...

edit---

outra coisa...esse codigo que vc postou nao compilou aqui não
usa esse codigo aqui e ve se funfa:


/*
* GLUT Shapes Demo
*
* Written by Nigel Stewart November 2003
*
* This program is test harness for the sphere, cone
* and torus shapes in GLUT.
*
* Spinning wireframe and smooth shaded shapes are
* displayed until the ESC or q key is pressed. The
* number of geometry stacks and slices can be adjusted
* using the + and - keys.
*/

#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <stdlib.h>
#include <math.h>

static int slices = 16;
static int stacks = 16;
//angle of rotation
float xpos = 0, ypos = 0, zpos = 0, xrot = 0, yrot = 0, angle=0.0;


/* GLUT callback Handlers */

static void resize(int width, int height)
{
const float ar = (float) width / (float) height;

glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity() ;
}
void camera (void) {
glRotatef(xrot,1.0,0.0,0.0); //rotate our camera on teh x-axis (left and right)
glRotatef(yrot,0.0,1.0,0.0); //rotate our camera on the y-axis (up and down)
glTranslated(-xpos,-ypos,-zpos); //translate the screen to the position of our camera
}
static void display(void)
{
const double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
const double a = t*90.0;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3d(0,0,1);

glLoadIdentity ();
gluLookAt ( 0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 ) ;
camera();

glRotated(45,0,1,0);





glPushMatrix();
glTranslated(-2.4,1.2,-6);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();


glPushMatrix();
glTranslated(0,1.2,-6);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidCone(1,1,slices,stacks);
glPopMatrix();

glPushMatrix();
glTranslated(2.4,1.2,-6);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidTorus(0.2,0.8,slices,stacks);
glPopMatrix();

glColor3d(1,0,0);

glPushMatrix();
glTranslated(-2.4,-1.2,-6);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutWireSphere(1,slices,stacks);
glPopMatrix();

glPushMatrix();
glTranslated(0,-1.2,-6);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutWireCone(1,1,slices,stacks);
glPopMatrix();

glPushMatrix();
glTranslated(2.4,-1.2,-6);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutWireTorus(0.2,0.8,slices,stacks);
glPopMatrix();




glutSwapBuffers();
angle++; //increase the angle
}






static void key(unsigned char key, int x, int y)
{
switch (key)
{
case 27 :

exit(0);
break;

case '+':
slices++;
stacks++;
break;

case 'q':
xrot += 1;
if (xrot >360) xrot -= 360;
break;
case 'z':
xrot -= 1;
if (xrot < -360) xrot += 360;
break;

case 'w':
{
float xrotrad, yrotrad;
yrotrad = (yrot / 180 * 3.141592654f);
xrotrad = (xrot / 180 * 3.141592654f);
xpos += float(sin(yrotrad)) ;
zpos -= float(cos(yrotrad)) ;
ypos -= float(sin(xrotrad)) ;
}
break;

case 's':
{
float xrotrad, yrotrad;
yrotrad = (yrot / 180 * 3.141592654f);
xrotrad = (xrot / 180 * 3.141592654f);
xpos -= float(sin(yrotrad));
zpos += float(cos(yrotrad)) ;
ypos += float(sin(xrotrad));
}
break;

case 'd':
yrot += 1;
if (yrot >360) yrot -= 360;
break;

case 'a':
yrot -= 1;
if (yrot < -360)yrot += 360;
break;

glutPostRedisplay();
}
}


static void idle(void)
{
glutPostRedisplay();
}

const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };

const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };

/* Program entry point */

int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(640,480);
glutInitWindowPosition(10,10);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

glutCreateWindow("GLUT Shapes");

glutReshapeFunc(resize);
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutIdleFunc(idle);

glClearColor(1,1,1,1);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);

glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);

glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);

glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);


glutMainLoop();

return 0;
}




5. Re: Problemas com OpenGL no linux [RESOLVIDO]

John
john.henrique

(usa Ubuntu)

Enviado em 22/08/2009 - 23:46h

Erros quando tento compilar o código que vc me passou:

undefined reference to `glutGet'
undefined reference to `gluLookAt'
undefined reference to `glutSolidSphere'
undefined reference to `glutSolidCone'
undefined reference to `glutSolidTorus'
undefined reference to `glutWireSphere'
undefined reference to `glutWireCone'
undefined reference to `glutWireTorus'
undefined reference to `glutSwapBuffers'
In function `idle':
undefined reference to `glutPostRedisplay'
In function `main':
undefined reference to `glutInit'
undefined reference to `glutInitWindowSize'
undefined reference to `glutInitWindowPosition'
undefined reference to `glutInitDisplayMode'
undefined reference to `glutCreateWindow'
undefined reference to `glutReshapeFunc'
undefined reference to `glutDisplayFunc'
undefined reference to `glutKeyboardFunc'
undefined reference to `glutIdleFunc'
undefined reference to `glutMainLoop'

parece que continua não encontrando as lib...

e naquele continua o problema do x, no xorg.cong nem havia a Section "Module", inseri junto com o load seguindo a idéia do restante do arquivo.

Eu não instalei os drivers da minha placa porque toda vez que o faço, ela fica instável e acaba sempre matando o x ao dar boot e ainda diminui a resolução da tela em muito...

pergunta: para matar o x é só dar killall x e depois start x(para iniciar ele novamente), ne?
não quer matar aqui, tiver que apelar e reiniciar



6. Re: Problemas com OpenGL no linux [RESOLVIDO]

Alex Fernando Ferreira
staltux

(usa Slackware)

Enviado em 23/08/2009 - 00:55h

depende do gerenciador que vc usa...no kde he killall kdm se eu nao me engano...
no gnome sei que he killall gdm

mas voltando ao codigo...sem driver proprietario creio que nao da...como o erro esta indicando,
main: X server has no OpenGL GLX extension
o X precisa de um modulo para gerenciar a parte 3D e quem da esse modulo he o driver da placa de video...openGL sem driver acho que nao vai dar nao...

edit------------

pede ajuda pro pessoal aqui pra instalar o driver...

e o codigo que eu postei tem que ser compilado com as libs configuradas como eu disse no meu primeiro posta la no codeblocks


7. Re: Problemas com OpenGL no linux [RESOLVIDO]

John
john.henrique

(usa Ubuntu)

Enviado em 23/08/2009 - 15:35h

Farei isto sim... obrigado

[edit]
instalar glutg3-dev do repositório
Cria projeto no codeblocks para opengl
na aba project->build options
vá em search directories
em linker
adicione /usr/include/GL
depois na aba linker settings
inclua em other linker options os parametros:
-lglut -lGLU -lGL
clica em ok
compila e roda






Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts