ness
22-01-2005, 16:04
Ich würde mich gern mit opnegl befassen. Bisher hab ich nur unter Windown programmiert, aber das sollte nicht das Problem sein, da es nur standard-c++ war. Nun hab ich aus dem Internet ne kleine Beispielsource gezogen und würde die kern kompilieren...
Nun bekomme ich bei make install (das ich leider per hand machen muss, siehe unten) einen haufen Fehlermeldungen. Source: main.c:
include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
extern int mousemotion;
extern int mousex, mousey;
extern int draw_type;
extern GLfloat xangle; /* in Drehung um */
extern GLfloat yangle;
//Modellposition
extern GLfloat posx, posy, posz;
void mouse(int button, int state, int x, int y);
void motion(int x, int y);
void keyb(unsigned char keyPressed, int x, int y);
void recalcModelPos(void);
void DrawScene(void);
void myinit();
int main(int argc, char *argv[])
{
//GLUT initialisieren, Fenster setzen
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
// eigene Initialisierungen
myinit();
//Callbacks setzen: Reaktion auf Mausklicks und -bewegungen, Tastaturaktivitäten
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutKeyboardFunc(keyb);
//Callback zum Zeichnen der GL-Funktion
glutDisplayFunc(DrawScene);
glutMainLoop();
return EXIT_SUCCESS;
} Implementierung:
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
// Zustandsvariablen
// Mausbewewung
int mousemotion;
int mousex, mousey;
int draw_type = 1;
// Initialisierung Modellorientierung
GLfloat xangle = 4; /* in Drehung um */
GLfloat yangle = 120;
//Modellposition
GLfloat posx = 0, posy = 0, posz = -400;
//Callback Funktion: Reaktion auf Mausclicks
void mouse(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
mousemotion = 1;
mousex = x;
mousey = y;
}
if (button == GLUT_LEFT_BUTTON && state == GLUT_UP) {
mousemotion = 0;
}
}
//Callback Funktion: Reaktion auf Mausbewegung
void motion(int x, int y)
{
if (mousemotion) {
xangle = xangle - (y - mousey);
yangle = yangle - (x - mousex);
mousex = x;
mousey = y;
// Szene neu zeichnen
glutPostRedisplay();
}
}
//Callback Funktion: Reaktion auf Tastendruck
void keyb(unsigned char keyPressed, int x, int y)
{
switch (keyPressed) {
case '1':
draw_type = 1;
break;
case '2':
draw_type = 2;
break;
case '3':
draw_type = 3;
break;
case '4':
draw_type = 4;
break;
case '5':
draw_type = 5;
break;
case '6':
draw_type = 6;
break;
case '7':
draw_type = 7;
break;
case '8':
draw_type = 8;
break;
case '9':
draw_type = 9;
break;
}
}
//neue Modellposition berechnen
void recalcModelPos(void)
{
glLoadIdentity();
glTranslatef(posx, posy, posz);
glRotatef(xangle, 1.0, 0.0, 0.0);
glRotatef(yangle, 0.0, 1.0, 0.0);
}
void DrawScene(void)
{
// Puffer löschen
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// neue Modellkoordinaten berechnen
recalcModelPos();
// Verschiedene Objekte zeichnen
switch (draw_type) {
case 1: // ZWEI PUNKTE
glBegin(GL_POINTS);
// 1. PUNKT
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-100.0f, 0.0f, -100.0f);
// 2. PUNKT
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(-100.0f, 100.0f, -100.0f);
glEnd();
break;
case 2: // EINE LINIE
glBegin(GL_LINES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-100.0f, 0.0f, -100.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(-100.0f, 100.0f, -100.0f);
glEnd();
break;
case 3: // ZWEI LINIEN
glBegin(GL_LINE_STRIP);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-100.0f, 0.0f, -100.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(-100.0f, 100.0f, -100.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(0.0f, 100.0f, -100.0f);
glEnd();
break;
case 4: // EIN LINIENZUG
glBegin(GL_LINE_LOOP);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-100.0f, 0.0f, -100.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(-100.0f, 100.0f, -100.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(0.0f, 100.0f, -100.0f);
glEnd();
break;
case 5: // EIN DREICK
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-100.0f, 0.0f, -100.0f);
glVertex3f(-100.0f, 100.0f, -100.0f);
glVertex3f(0.0f, 100.0f, -100.0f);
glEnd();
break;
case 6: // ZWEI DREIECKE
glBegin(GL_TRIANGLE_STRIP);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-100.0f, 0.0f, -100.0f);
glVertex3f(-100.0f, 100.0f, -100.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(0.0f, 0.0f, -100.0f);
glVertex3f(0.0f, 100.0f, -100.0f);
glEnd();
break;
case 7: // ZWEI DREIECKE
glBegin(GL_TRIANGLE_FAN);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 0.0f, -100.0f);
glColor3f(1.0f, 0.03, 0.0f);
glVertex3f(-100.0f, 0.0f, -100.0f);
glColor3f(.0f, 1.0f, 0.0f);
glVertex3f(-100.0f, 100.0f, -100.0f);
glColor3f(.0f, 0.0f, 1.0f);
glVertex3f(50.0f, 50.0f, -100.0f);
glEnd();
break;
case 8: // EIN VIERECK
glBegin(GL_QUADS);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 0.0f, -100.0f);
glVertex3f(100.0f, 0.0f, -100.0f);
glVertex3f(100.0f, 100.0f, -100.0f);
glVertex3f(0.0f, 100.0f, -100.0f);
glEnd();
break;
case 9: // EIN FÜNFECK
glBegin(GL_POLYGON);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 0.0f, -100.0f);
glVertex3f(100.0f, 0.0f, -100.0f);
glVertex3f(50.0f, 100.0f, -100.0f);
glVertex3f(100.0f, 100.0f, -100.0f);
glVertex3f(0.0f, 100.0f, -100.0f);
glEnd();
break;
}
// Szene neu zeichnen
glutPostRedisplay();
// Vordergrund- und Hintergrundpuffer wechseln
glutSwapBuffers();
}
//eigene Initialisierungsfunktion
void myinit()
{
GLfloat light_position[] = { 0.0, 0.0, -1.0, 1.0 };
//erstes GL-Light setzen
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_LIGHT0);
//Z-Puffer aktivieren
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
// Matritzen setzen
glMatrixMode(GL_PROJECTION);
// Sichtpyramide erstellen
gluPerspective(60.0, 1.0, 1.0, 1000.0);
glMatrixMode(GL_MODELVIEW);
gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.);
}
Das sollte nicht das Problem sein. Nun die Fehler beim generieren: 1.: die Funktionen glutPostRedisplay, glLoadIdenty, glClearColor und glLightfv sind unbekannt.
Dann bekomme ich noch einen Riesenhaufen nicht vorhandene Deklaration Fehler, was nat. daran liegt, dass die Bibliotheken nicht mit gelinkt werden... Wie ändere ich das? Unter anjuta hab ich keine Einstellung gefunden.
Mal angenommen ich kann das kompilieren, würde dann mein (schwer erkämpfte) grafikbeschleunigung greifen, oder muss ich dazu was bestimmtes einstellen.
Drittens und letztens, ein Anjuta-spezifisches Problem: installieren kann ich nur als root, Anjuta versucht über su --comand 'make install' zu gehen. Das klappt nicht, weil es su -c 'make install' heißen sollte. Wie sag ich Anjuta das?
Nun bekomme ich bei make install (das ich leider per hand machen muss, siehe unten) einen haufen Fehlermeldungen. Source: main.c:
include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
extern int mousemotion;
extern int mousex, mousey;
extern int draw_type;
extern GLfloat xangle; /* in Drehung um */
extern GLfloat yangle;
//Modellposition
extern GLfloat posx, posy, posz;
void mouse(int button, int state, int x, int y);
void motion(int x, int y);
void keyb(unsigned char keyPressed, int x, int y);
void recalcModelPos(void);
void DrawScene(void);
void myinit();
int main(int argc, char *argv[])
{
//GLUT initialisieren, Fenster setzen
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
// eigene Initialisierungen
myinit();
//Callbacks setzen: Reaktion auf Mausklicks und -bewegungen, Tastaturaktivitäten
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutKeyboardFunc(keyb);
//Callback zum Zeichnen der GL-Funktion
glutDisplayFunc(DrawScene);
glutMainLoop();
return EXIT_SUCCESS;
} Implementierung:
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
// Zustandsvariablen
// Mausbewewung
int mousemotion;
int mousex, mousey;
int draw_type = 1;
// Initialisierung Modellorientierung
GLfloat xangle = 4; /* in Drehung um */
GLfloat yangle = 120;
//Modellposition
GLfloat posx = 0, posy = 0, posz = -400;
//Callback Funktion: Reaktion auf Mausclicks
void mouse(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
mousemotion = 1;
mousex = x;
mousey = y;
}
if (button == GLUT_LEFT_BUTTON && state == GLUT_UP) {
mousemotion = 0;
}
}
//Callback Funktion: Reaktion auf Mausbewegung
void motion(int x, int y)
{
if (mousemotion) {
xangle = xangle - (y - mousey);
yangle = yangle - (x - mousex);
mousex = x;
mousey = y;
// Szene neu zeichnen
glutPostRedisplay();
}
}
//Callback Funktion: Reaktion auf Tastendruck
void keyb(unsigned char keyPressed, int x, int y)
{
switch (keyPressed) {
case '1':
draw_type = 1;
break;
case '2':
draw_type = 2;
break;
case '3':
draw_type = 3;
break;
case '4':
draw_type = 4;
break;
case '5':
draw_type = 5;
break;
case '6':
draw_type = 6;
break;
case '7':
draw_type = 7;
break;
case '8':
draw_type = 8;
break;
case '9':
draw_type = 9;
break;
}
}
//neue Modellposition berechnen
void recalcModelPos(void)
{
glLoadIdentity();
glTranslatef(posx, posy, posz);
glRotatef(xangle, 1.0, 0.0, 0.0);
glRotatef(yangle, 0.0, 1.0, 0.0);
}
void DrawScene(void)
{
// Puffer löschen
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// neue Modellkoordinaten berechnen
recalcModelPos();
// Verschiedene Objekte zeichnen
switch (draw_type) {
case 1: // ZWEI PUNKTE
glBegin(GL_POINTS);
// 1. PUNKT
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-100.0f, 0.0f, -100.0f);
// 2. PUNKT
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(-100.0f, 100.0f, -100.0f);
glEnd();
break;
case 2: // EINE LINIE
glBegin(GL_LINES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-100.0f, 0.0f, -100.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(-100.0f, 100.0f, -100.0f);
glEnd();
break;
case 3: // ZWEI LINIEN
glBegin(GL_LINE_STRIP);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-100.0f, 0.0f, -100.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(-100.0f, 100.0f, -100.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(0.0f, 100.0f, -100.0f);
glEnd();
break;
case 4: // EIN LINIENZUG
glBegin(GL_LINE_LOOP);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-100.0f, 0.0f, -100.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(-100.0f, 100.0f, -100.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(0.0f, 100.0f, -100.0f);
glEnd();
break;
case 5: // EIN DREICK
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-100.0f, 0.0f, -100.0f);
glVertex3f(-100.0f, 100.0f, -100.0f);
glVertex3f(0.0f, 100.0f, -100.0f);
glEnd();
break;
case 6: // ZWEI DREIECKE
glBegin(GL_TRIANGLE_STRIP);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-100.0f, 0.0f, -100.0f);
glVertex3f(-100.0f, 100.0f, -100.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(0.0f, 0.0f, -100.0f);
glVertex3f(0.0f, 100.0f, -100.0f);
glEnd();
break;
case 7: // ZWEI DREIECKE
glBegin(GL_TRIANGLE_FAN);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 0.0f, -100.0f);
glColor3f(1.0f, 0.03, 0.0f);
glVertex3f(-100.0f, 0.0f, -100.0f);
glColor3f(.0f, 1.0f, 0.0f);
glVertex3f(-100.0f, 100.0f, -100.0f);
glColor3f(.0f, 0.0f, 1.0f);
glVertex3f(50.0f, 50.0f, -100.0f);
glEnd();
break;
case 8: // EIN VIERECK
glBegin(GL_QUADS);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 0.0f, -100.0f);
glVertex3f(100.0f, 0.0f, -100.0f);
glVertex3f(100.0f, 100.0f, -100.0f);
glVertex3f(0.0f, 100.0f, -100.0f);
glEnd();
break;
case 9: // EIN FÜNFECK
glBegin(GL_POLYGON);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 0.0f, -100.0f);
glVertex3f(100.0f, 0.0f, -100.0f);
glVertex3f(50.0f, 100.0f, -100.0f);
glVertex3f(100.0f, 100.0f, -100.0f);
glVertex3f(0.0f, 100.0f, -100.0f);
glEnd();
break;
}
// Szene neu zeichnen
glutPostRedisplay();
// Vordergrund- und Hintergrundpuffer wechseln
glutSwapBuffers();
}
//eigene Initialisierungsfunktion
void myinit()
{
GLfloat light_position[] = { 0.0, 0.0, -1.0, 1.0 };
//erstes GL-Light setzen
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_LIGHT0);
//Z-Puffer aktivieren
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
// Matritzen setzen
glMatrixMode(GL_PROJECTION);
// Sichtpyramide erstellen
gluPerspective(60.0, 1.0, 1.0, 1000.0);
glMatrixMode(GL_MODELVIEW);
gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.);
}
Das sollte nicht das Problem sein. Nun die Fehler beim generieren: 1.: die Funktionen glutPostRedisplay, glLoadIdenty, glClearColor und glLightfv sind unbekannt.
Dann bekomme ich noch einen Riesenhaufen nicht vorhandene Deklaration Fehler, was nat. daran liegt, dass die Bibliotheken nicht mit gelinkt werden... Wie ändere ich das? Unter anjuta hab ich keine Einstellung gefunden.
Mal angenommen ich kann das kompilieren, würde dann mein (schwer erkämpfte) grafikbeschleunigung greifen, oder muss ich dazu was bestimmtes einstellen.
Drittens und letztens, ein Anjuta-spezifisches Problem: installieren kann ich nur als root, Anjuta versucht über su --comand 'make install' zu gehen. Das klappt nicht, weil es su -c 'make install' heißen sollte. Wie sag ich Anjuta das?