Markus Rechberger / Open GL
 
StartSeite | MarkusRechberger/ | Neues | TestSeite | ForumSeite | Teilnehmer | Kategorien | Index | Hilfe | Einstellungen | Ändern

Veränderung (zum vorhergehenden Autor) (Änderung, Korrektur, Normalansicht)

Verändert: 1c1,136
Beschreibe hier die neue Seite.
Kleines selbst entwickeltes OpenGL Beispiel:

Aufgabe:
* Erstellen eines Kugel/Spheregerüsts mittels glut/opengl

[[Code]
#include <stdio.h>
#include <GL/glut.h>
#include <math.h>

static GLfloat spin=0.0;
GLfloat d=0.0;
GLfloat e=0.0;
GLfloat a=0.0;
int autorotate=0;
void display(void){
GLdouble eqn[4] = {0.0,1.0,0.0,0.0};
GLdouble eqn2[4] = {1.0,0.0,0.0,0.0};
GLfloat circle;
GLfloat i;
GLfloat oldx;
GLfloat oldy;
GLfloat alpha;
GLfloat length;
glMatrixMode({GL PROJECTION}?);
glLoadIdentity();
gluPerspective(180.0f,(GLfloat)320/(GLfloat)240, .0f ,0.0f);
glMatrixMode({GL MODELVIEW}?);
glLoadIdentity();
glClearColor(0,0,0.2,0);
glColor3f (0, 0, 0.9);
glClear({GL COLOR BUFFER BIT}?);
glFlush();
if(autorotate==1){
a++;
glRotatef(a,1,1,1);
if(a==360){
a=0;
}
}

glRotatef(d,1,0,0);
glRotatef(e,0,1,0);
glBegin({GL LINES}?);
glVertex3f(0,0,0);
glVertex3f(0,1,0);
glVertex3f(0,0,0);
glVertex3f(0,0,1);
glVertex3f(0,0,0);
glVertex3f(1,0,0);
glEnd();
for(i=1;i<360;i+=5){
glBegin({GL LINES}?);
for(circle=0;circle<=360;circle++){
glVertex3f(sin(circle/180*{M PI}?),cos(circle/180*{M PI}?),0);

}
glEnd();
glRotatef(5,0,1,0);
}
for(i=-1;i<=1;i+=0.1){
length=cos(asin(i));
glBegin({GL LINES}?);
for(circle=0;circle<=360;circle++){
if(length!=0){
glVertex3f(length*sin(circle/180*{M PI}?),i,length*cos(circle/180*{M PI}?));
}
}
glEnd();
}
glFlush();
glutSwapBuffers();
}

void keyboard(int key, int x, int y){

// glMatrixMode({GL MODELVIEW}?);
// glLoadIdentity();
switch(key){
case {GLUT KEY UP}?:
printf("key up!\n");
d--;
break;
case {GLUT KEY DOWN}?:
printf("key down!\n");
d++;
break;
case {GLUT KEY LEFT}?:
printf("key left!\n");
e--;
break;
case {GLUT KEY RIGHT}?:
printf("key right!\n");
e++;
break;
case {GLUT KEY PAGE UP}?:
autorotate=1;
a++;
break;
case {GLUT KEY PAGE DOWN}?:
autorotate=0;
break;
}
display();
}


int main(int argc, char **argv){
glutInit(&argc,argv);
glutInitDisplayMode({GLUT DOUBLE}?| {GLUT RGB}?| {GLUT DEPTH}?);
glutInitWindowSize(640,480);
glEnable({GL DEPTH TEST}?);
glEnable({GL TEXTURE 2D}?);
glMatrixMode({GL PROJECTION}?);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)640/(GLfloat)480, .5f ,150.0f);
glMatrixMode({GL MODELVIEW}?);
glLoadIdentity();
glMatrixMode({GL MODELVIEW}?);
glLoadIdentity();
glutInitWindowPosition(0,0);
glutCreateWindow("revenger's tutorial");
glutSpecialFunc(keyboard);
// display();
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
return(0);
}
]

Dazugehörige Makefile
[[Code]
all:
gcc main.c -o main -lglut
]

Kleines selbst entwickeltes OpenGL Beispiel:

Aufgabe:

 * Erstellen eines Kugel/Spheregerüsts mittels glut/opengl

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

static GLfloat spin=0.0;
GLfloat d=0.0;
GLfloat e=0.0;
GLfloat a=0.0;
int autorotate=0;
void display(void){
        GLdouble eqn[4] = {0.0,1.0,0.0,0.0};
        GLdouble eqn2[4] = {1.0,0.0,0.0,0.0};
        GLfloat circle;
        GLfloat i;
        GLfloat oldx;
        GLfloat oldy;
        GLfloat alpha;
        GLfloat length;
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(180.0f,(GLfloat)320/(GLfloat)240, .0f ,0.0f);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glClearColor(0,0,0.2,0);
        glColor3f (0, 0, 0.9);
        glClear(GL_COLOR_BUFFER_BIT);
        glFlush();
        if(autorotate==1){
                a++;
                glRotatef(a,1,1,1);
                if(a==360){
                        a=0;
                }
        }

          glRotatef(d,1,0,0);
          glRotatef(e,0,1,0);
          glBegin(GL_LINES);
          glVertex3f(0,0,0);
          glVertex3f(0,1,0);
          glVertex3f(0,0,0);
          glVertex3f(0,0,1);
          glVertex3f(0,0,0);
          glVertex3f(1,0,0);
          glEnd();
          for(i=1;i<360;i+=5){
                  glBegin(GL_LINES);
                  for(circle=0;circle<=360;circle++){
                          glVertex3f(sin(circle/180*M_PI),cos(circle/180*M_PI),0);

                  }
                  glEnd();
                  glRotatef(5,0,1,0);
          }
         for(i=-1;i<=1;i+=0.1){
                 length=cos(asin(i));
                 glBegin(GL_LINES);
                 for(circle=0;circle<=360;circle++){
                         if(length!=0){
                                  glVertex3f(length*sin(circle/180*M_PI),i,length*cos(circle/180*M_PI));
                         }
                 }
                 glEnd();
        }
        glFlush();
        glutSwapBuffers();
}

void keyboard(int key, int x, int y){

//        glMatrixMode(GL_MODELVIEW);
//        glLoadIdentity();
        switch(key){
               case GLUT_KEY_UP:
                       printf("key up!\n");
                       d--;
                       break;
               case GLUT_KEY_DOWN:
                       printf("key down!\n");
                       d++;
                       break;
               case GLUT_KEY_LEFT:
                       printf("key left!\n");
                       e--;
                       break;
               case GLUT_KEY_RIGHT:
                       printf("key right!\n");
                       e++;
                       break;
               case GLUT_KEY_PAGE_UP:
                       autorotate=1;
                       a++;
                       break;
               case GLUT_KEY_PAGE_DOWN:
                       autorotate=0;
                       break;
        }
        display();
}


int main(int argc, char **argv){
        glutInit(&argc,argv);
        glutInitDisplayMode(GLUT_DOUBLE| GLUT_RGB| GLUT_DEPTH);
        glutInitWindowSize(640,480);
         glEnable(GL_DEPTH_TEST);
         glEnable(GL_TEXTURE_2D);
         glMatrixMode(GL_PROJECTION);
         glLoadIdentity();
         gluPerspective(45.0f,(GLfloat)640/(GLfloat)480, .5f ,150.0f);
         glMatrixMode(GL_MODELVIEW);
         glLoadIdentity();
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glutInitWindowPosition(0,0);
        glutCreateWindow("revenger's tutorial");
        glutSpecialFunc(keyboard);
//        display();
        glutDisplayFunc(display);
        glutIdleFunc(display);
        glutMainLoop();
        return(0);
}

Dazugehörige Makefile
all:
        gcc main.c -o main -lglut


StartSeite | MarkusRechberger/ | Neues | TestSeite | ForumSeite | Teilnehmer | Kategorien | Index | Hilfe | Einstellungen | Ändern
Text dieser Seite ändern (zuletzt geändert: 11. Oktober 2004 14:26 (diff))
Suchbegriff: gesucht wird
im Titel
im Text