Skip to content
Snippets Groups Projects
Commit ce735cdb authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Material für Praktikumsversuch 2: egal.txt, orbit-1.c, textured-spheres.[ch], Texturen

parent f11c50e1
Branches
No related tags found
No related merge requests found
Showing
with 371 additions and 194 deletions
GNU/Linux
~~~~~~~~~
Compilieren: gcc -Wall -O cube-3c.c opengl-magic-double.c \
-lGL -lGLU -lglut -o cube-3c
Aufrufen: ./cube-3c
MacOS
~~~~~
Compilieren: gcc -Wall -O cube-3c.c opengl-magic-double.c \
-framework OpenGL -framework GLUT -o cube-3c
Aufrufen: ./cube-3c
Cygwin mit X11
~~~~~~~~~~~~~~
Compilieren: gcc -Wall -O cube-3c.c opengl-magic-double.c \
-lGL -lGLU -lglut -o cube-3c
Aufrufen: DISPLAY=:0.0 ./cube-3c
oder:
einmalig: export DISPLAY=:0.0
danach: ./cube-3c
Vorher einmalig: X-Server starten
XWin -multiwindow &
Cygwin ohne X11
~~~~~~~~~~~~~~~
Compilieren: i686-pc-mingw32-gcc -I freeglut/include -L freeglut/lib \
-Wall -O cube-3c.c opengl-magic-double.c \
-lOpenGL32 -lGLU32 -lfreeglut -o cube-3c
Aufrufen: ./cube-3c
MinGW ohne X11
~~~~~~~~~~~~~~
Compilieren: gcc -I freeglut/include -L freeglut/lib \
-Wall -O cube-3c.c opengl-magic-double.c \
-lOpenGL32 -lGLU32 -lfreeglut -o cube-3c
Aufrufen: ./cube-3c
../common/egal.txt
\ No newline at end of file
#if defined(__APPLE__) || defined(MACOSX)
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#endif
#include "opengl-magic.h"
void init_opengl (int *argcp, char **argv, char *window_name)
{
glutInit (argcp, argv);
glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize (1024, 768);
glutCreateWindow (window_name);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (20.0, -1.33333, 3.0, 7.0);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
glTranslatef (0.0, 0.0, -5.0);
glClearColor (0.0, 0.0, 0.0, 0.0);
glEnable (GL_DEPTH_TEST);
glEnable (GL_LIGHTING);
glEnable (GL_LIGHT0);
static GLfloat light0_position[] = { 1.0, 0.0, 1.0, 0.0 };
glLightfv (GL_LIGHT0, GL_POSITION, light0_position);
}
void set_material_color (float r, float g, float b)
{
GLfloat color[] = { r, g, b };
glMaterialfv (GL_FRONT, GL_AMBIENT, color);
glMaterialfv (GL_FRONT, GL_DIFFUSE, color);
}
#if defined(__APPLE__) || defined(MACOSX)
void glutSolidCylinder (double radius, double height, int slices, int stacks)
{
GLUquadricObj *q = gluNewQuadric ();
gluCylinder (q, radius, radius, height, slices, stacks);
gluDeleteQuadric (q);
}
#endif
../common/opengl-magic.c
\ No newline at end of file
#ifndef OPENGL_MAGIC_H
#define OPENGL_MAGIC_H
extern void init_opengl (int *argcp, char **argv, char *window_name);
extern void set_material_color (float r, float g, float b);
#ifdef __MACOSX__
extern void glutSolidCylinder (double radius, double height, int slices, int stacks);
#endif
#endif /* OPENGL_MAGIC_H */
../common/opengl-magic.h
\ No newline at end of file
../common/earth-texture.png
\ No newline at end of file
../common/egal.txt
\ No newline at end of file
../common/moon-texture.png
\ No newline at end of file
../common/opengl-magic.c
\ No newline at end of file
../common/opengl-magic.h
\ No newline at end of file
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include "opengl-magic.h"
#include "textured-spheres.h"
float t = 0.0;
GLuint earth_texture, moon_texture;
void draw_earth (void)
{
glPushMatrix ();
glRotatef (90, 1.0, 0.0, 0.0);
glRotatef (100.0 * t, 0.0, 0.0, 1.0);
draw_textured_sphere (earth_texture, 0.25512, 63, 20);
glPopMatrix ();
}
void draw_moon (void)
{
glPushMatrix ();
glRotatef (90, 1.0, 0.0, 0.0);
glRotatef (-90, 0.0, 0.0, 1.0);
draw_textured_sphere (moon_texture, 0.06952, 31, 10);
glPopMatrix ();
}
void draw (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix ();
glRotatef (23.44, 1.0, 0.0, -1.0);
draw_earth ();
glRotatef (5.145, 0.0, 1.0, 1.0);
glRotatef (30.0 * t, 0.0, -1.0, 0.0);
glTranslatef (0.9, 0.0, 0.0);
draw_moon ();
glPopMatrix ();
glFlush ();
glutSwapBuffers ();
}
void timer_handler (int value)
{
t += 0.05;
glutPostRedisplay ();
glutTimerFunc (50, timer_handler, 0);
}
int main (int argc, char **argv)
{
init_opengl (&argc, argv, "Orbit");
init_texture ("earth-texture.png", &earth_texture);
init_texture ("moon-texture.png", &moon_texture);
glutDisplayFunc (draw);
glutTimerFunc (50, timer_handler, 0);
glutMainLoop ();
return 0;
}
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/freeglut.h>
#include <math.h>
#include "opengl-magic.h"
#define phi0 1.0 /* geg. Anfangswert */
#define omega0 0.0 /* geg. Anfangswert */
#define dt 0.05
#define g 9.81
#define l 1.0
double t = 0.0;
double phi = phi0;
double omega = omega0;
void draw (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
set_material_color (0.8, 0.8, 1.0);
glPushMatrix ();
glRotatef (90, 1.0, 0.0, 0.0);
glTranslatef (0.0, 0.0, -0.75);
glRotatef (180.0 + phi / M_PI * 180.0, 0.0, 1.0, 0.0);
glTranslatef (0.0, 0.0, -1.0);
glutSolidCylinder (0.01, l, 13, 1);
glutSolidSphere (0.1, 31, 10);
glPopMatrix ();
glFlush ();
glutSwapBuffers ();
}
void timer_handler (int value)
{
t += dt;
glutPostRedisplay ();
glutTimerFunc (50, timer_handler, 0);
}
int main (int argc, char **argv)
{
init_opengl (&argc, argv, "Pendulum");
glutDisplayFunc (draw);
glutTimerFunc (50, timer_handler, 0);
glutMainLoop ();
return 0;
}
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/freeglut.h>
#include <math.h>
#include "opengl-magic.h"
#define phi0 1.0 /* geg. Anfangswert */
#define omega0 0.0 /* geg. Anfangswert */
#define dt 0.05
#define g 9.81
#define l 1.0
double t = 0.0;
double phi = phi0;
double omega = omega0;
void draw (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
set_material_color (0.8, 0.8, 1.0);
glPushMatrix ();
glRotatef (90, 1.0, 0.0, 0.0);
glTranslatef (0.0, 0.0, -0.75);
glRotatef (180.0 + phi / M_PI * 180.0, 0.0, 1.0, 0.0);
glTranslatef (0.0, 0.0, -1.0);
glutSolidCylinder (0.01, l, 13, 1);
glutSolidSphere (0.1, 31, 10);
glPopMatrix ();
glFlush ();
glutSwapBuffers ();
}
void timer_handler (int value)
{
t += dt;
phi += dt * omega;
omega += dt * (-g / l) * sin (phi);
glutPostRedisplay ();
glutTimerFunc (50, timer_handler, 0);
}
int main (int argc, char **argv)
{
init_opengl (&argc, argv, "Pendulum");
glutDisplayFunc (draw);
glutTimerFunc (50, timer_handler, 0);
glutMainLoop ();
return 0;
}
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/freeglut.h>
#include <math.h>
#include "opengl-magic.h"
#define phi0 1.0 /* geg. Anfangswert */
#define omega0 0.0 /* geg. Anfangswert */
#define dt 0.05
#define g 9.81
#define l 1.0
double t = 0.0;
double phi = phi0;
double omega = omega0;
void draw (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
set_material_color (1.0, 1.0, 0.8);
glPushMatrix ();
glRotatef (90, 1.0, 0.0, 0.0);
glTranslatef (0.0, 0.0, -0.75);
glRotatef (180.0 + phi / M_PI * 180.0, 0.0, 1.0, 0.0);
glTranslatef (0.0, 0.0, -1.0);
glutSolidCylinder (0.01, l, 13, 1);
glutSolidSphere (0.1, 31, 10);
glPopMatrix ();
glFlush ();
glutSwapBuffers ();
}
void timer_handler (int value)
{
t += dt;
phi += dt * omega;
omega += dt * (-g / l) * phi;
glutPostRedisplay ();
glutTimerFunc (50, timer_handler, 0);
}
int main (int argc, char **argv)
{
init_opengl (&argc, argv, "Pendulum");
glutDisplayFunc (draw);
glutTimerFunc (50, timer_handler, 0);
glutMainLoop ();
return 0;
}
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/freeglut.h>
#include <math.h>
#include "opengl-magic.h"
#define phi0 0.5 /* geg. Anfangswert */
#define omega0 0.0 /* geg. Anfangswert */
#define dt 0.05
#define g 9.81
#define l 1.0
double t = 0.0;
double phi_with_sin = phi0;
double omega_with_sin= omega0;
double phi_without_sin = phi0;
double omega_without_sin= omega0;
void draw_pendulum (double phi)
{
glPushMatrix ();
glRotatef (90, 1.0, 0.0, 0.0);
glTranslatef (0.0, 0.0, -0.75);
glRotatef (180.0 + phi / M_PI * 180.0, 0.0, 1.0, 0.0);
glTranslatef (0.0, 0.0, -1.0);
glutSolidCylinder (0.01, 1.0, 13, 1);
glutSolidSphere (0.1, 31, 10);
glPopMatrix ();
glutSwapBuffers ();
}
void draw (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
set_material_color (0.8, 0.8, 1.0);
draw_pendulum (phi_with_sin);
set_material_color (1.0, 0.8, 0.8);
draw_pendulum (phi_without_sin);
set_material_color (0.8, 1.0, 0.8);
double A = phi0;
double B = 0.5 * M_PI; /* 90° */
double phi_analytic = A * sin (sqrt (g / l) * t + B);
draw_pendulum (phi_analytic);
glFlush ();
}
void timer_handler (int value)
{
t += dt;
phi_with_sin += dt * omega_with_sin; /* geg. Differentialgleichung */
omega_with_sin += - dt * g / l * sin (phi_with_sin); /* geg. Differentialgleichung */
/* _ohne_ Kleinwinkelnäherung */
phi_without_sin += dt * omega_without_sin; /* geg. Differentialgleichung */
omega_without_sin += - dt * g / l * phi_without_sin; /* geg. Differentialgleichung */
/* _mit_ Kleinwinkelnäherung */
glutPostRedisplay ();
glutTimerFunc (50, timer_handler, 0);
}
int main (int argc, char **argv)
{
init_opengl (&argc, argv, "Pendulum");
glutDisplayFunc (draw);
glutTimerFunc (50, timer_handler, 0);
glutPostRedisplay ();
glutMainLoop ();
return 0;
}
../common/textured-spheres.c
\ No newline at end of file
../common/textured-spheres.h
\ No newline at end of file
GNU/Linux
~~~~~~~~~
Compilieren: gcc -Wall -O cube-3c.c opengl-magic-double.c \
-lGL -lGLU -lglut -o cube-3c
Aufrufen: ./cube-3c
MacOS
~~~~~
Compilieren: gcc -Wall -O cube-3c.c opengl-magic-double.c \
-framework OpenGL -framework GLUT -o cube-3c
Aufrufen: ./cube-3c
Cygwin mit X11
~~~~~~~~~~~~~~
Compilieren: gcc -Wall -O cube-3c.c opengl-magic-double.c \
-lGL -lGLU -lglut -o cube-3c
Aufrufen: DISPLAY=:0.0 ./cube-3c
oder:
einmalig: export DISPLAY=:0.0
danach: ./cube-3c
Vorher einmalig: X-Server starten
XWin -multiwindow &
Cygwin ohne X11
~~~~~~~~~~~~~~~
Compilieren: i686-pc-mingw32-gcc -I freeglut/include -L freeglut/lib \
-Wall -O cube-3c.c opengl-magic-double.c \
-lOpenGL32 -lGLU32 -lfreeglut -o cube-3c
Aufrufen: ./cube-3c
MinGW ohne X11
~~~~~~~~~~~~~~
Compilieren: gcc -I freeglut/include -L freeglut/lib \
-Wall -O cube-3c.c opengl-magic-double.c \
-lOpenGL32 -lGLU32 -lfreeglut -o cube-3c
Aufrufen: ./cube-3c
#if defined(__APPLE__) || defined(MACOSX)
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#endif
#include "opengl-magic.h"
void init_opengl (int *argcp, char **argv, char *window_name)
{
glutInit (argcp, argv);
glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize (1024, 768);
glutCreateWindow (window_name);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (20.0, -1.33333, 3.0, 7.0);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
glTranslatef (0.0, 0.0, -5.0);
glClearColor (0.0, 0.0, 0.0, 0.0);
glEnable (GL_DEPTH_TEST);
glEnable (GL_LIGHTING);
glEnable (GL_LIGHT0);
static GLfloat light0_position[] = { 1.0, 0.0, 1.0, 0.0 };
glLightfv (GL_LIGHT0, GL_POSITION, light0_position);
}
void set_material_color (float r, float g, float b)
{
GLfloat color[] = { r, g, b };
glMaterialfv (GL_FRONT, GL_AMBIENT, color);
glMaterialfv (GL_FRONT, GL_DIFFUSE, color);
}
#if defined(__APPLE__) || defined(MACOSX)
void glutSolidCylinder (double radius, double height, int slices, int stacks)
{
GLUquadricObj *q = gluNewQuadric ();
gluCylinder (q, radius, radius, height, slices, stacks);
gluDeleteQuadric (q);
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment