From 091f2e382d8070ded766ceb35cfcb5c9aab0c4e7 Mon Sep 17 00:00:00 2001 From: eri451 Date: Tue, 21 Jan 2014 07:19:34 +0100 Subject: [PATCH 1/8] inital commit --- lesson02/lesson2.c | 266 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 266 insertions(+) create mode 100755 lesson02/lesson2.c diff --git a/lesson02/lesson2.c b/lesson02/lesson2.c new file mode 100755 index 0000000..fe263f2 --- /dev/null +++ b/lesson02/lesson2.c @@ -0,0 +1,266 @@ +// +// This code was created by Jeff Molofee '99 (ported to Linux/GLUT by Richard Campbell '99) +// +// If you've found this code useful, please let me know. +// +// Visit me at www.demonews.com/hosted/nehe +// (email Richard Campbell at ulmont@bellsouth.net) +// +#include // Header File For The GLUT Library +#include // Header File For The OpenGL32 Library +#include // Header File For The GLu32 Library +#include // Header File For sleeping. + +#include + +/* ASCII code for the escape key. */ +#define ESCAPE 27 +#define PAGE_UP 73 +#define PAGE_DOWN 81 +#define UP_ARROW 72 +#define DOWN_ARROW 80 +#define LEFT_ARROW 75 +#define RIGHT_ARROW 77 + +/* The number of our GLUT window */ +int window; + +float xrot = 0.0f; +float yrot = 0.0f; + +/* A general OpenGL initialization function. Sets all of the initial parameters. */ +void InitGL(int Width, int Height) // We call this right after our OpenGL window is created. +{ + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black + glClearDepth(1.0); // Enables Clearing Of The Depth Buffer + glDepthFunc(GL_LESS); // The Type Of Depth Test To Do + glEnable(GL_DEPTH_TEST); // Enables Depth Testing + glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); // Reset The Projection Matrix + + gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f); // Calculate The Aspect Ratio Of The Window + + glMatrixMode(GL_MODELVIEW); + +} + +/* The function called when our window is resized (which shouldn't happen, because we're fullscreen) */ +void ReSizeGLScene(int Width, int Height) +{ + if (Height==0) // Prevent A Divide By Zero If The Window Is Too Small + Height=1; + + glViewport(0, 0, Width, Height); // Reset The Current Viewport And Perspective Transformation + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f); + glMatrixMode(GL_MODELVIEW); +} + +/* The main drawing function. */ +void DrawGLScene() +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer + glLoadIdentity(); // Reset The View + + + glTranslatef(0.0f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0 + + glRotatef(xrot, 1.0f, 0.0f, 0.0f); + glRotatef(yrot, 0.0f, 1.0f, 0.0f); + + // draw a square (quadrilateral) + glBegin(GL_QUADS); // start drawing a polygon (4 sided) + + /* --- Top --- */ + glColor3f( 1.0f, 1.0f, 0.0f); + glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Front + + glColor3f( 1.0f, 1.0f, 1.0f); + glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Front + + glColor3f( 1.0f, 0.0f, 1.0f); + glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Back + + glColor3f( 1.0f, 0.0f, 0.0f); + glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Back + + + /* --- Left Side --- */ + glColor3f( 0.0f, 0.0f, 0.0f); + glVertex3f(-1.0f,-1.0f,-1.0f); // Left Side Bottom Back + + glColor3f( 0.0f, 1.0f, 0.0f); + glVertex3f(-1.0f,-1.0f, 1.0f); // Left Side Bottom Front + + glColor3f( 1.0f, 1.0f, 0.0f); + glVertex3f(-1.0f, 1.0f, 1.0f); // Left Side Top Front + + glColor3f( 1.0f, 0.0f, 0.0f); + glVertex3f(-1.0f, 1.0f,-1.0f); // Left Side Top Back + + + /* --- Right Side --- */ + glColor3f( 0.0f, 0.0f, 1.0f); + glVertex3f( 1.0f,-1.0f,-1.0f); // Right Side Bottom Back + + glColor3f( 0.0f, 1.0f, 1.0f); + glVertex3f( 1.0f,-1.0f, 1.0f); // Right Side Bottom Front + + glColor3f( 1.0f, 1.0f, 1.0f); + glVertex3f( 1.0f, 1.0f, 1.0f); // Right Side Top Front + + glColor3f( 1.0f, 0.0f, 1.0f); + glVertex3f( 1.0f, 1.0f,-1.0f); // Right Side Top Back + + + /* --- Back Side --- */ + glColor3f( 0.0f, 0.0f, 1.0f); + glVertex3f( 1.0f,-1.0f,-1.0f); // Back Right Side Bottom + + glColor3f( 0.0f, 0.0f, 0.0f); + glVertex3f(-1.0f,-1.0f,-1.0f); // Back Left Side Bottom + + glColor3f( 1.0f, 0.0f, 0.0f); + glVertex3f(-1.0f, 1.0f,-1.0f); // Back Left Side Top + + glColor3f( 1.0f, 0.0f, 1.0f); + glVertex3f( 1.0f, 1.0f,-1.0f); // Back Right Side Top + + + /* --- Front --- */ + glColor3f( 0.0f, 1.0f, 1.0f); + glVertex3f( 1.0f,-1.0f, 1.0f); // Front Right Side Bottom + + glColor3f( 0.0f, 1.0f, 0.0f); + glVertex3f(-1.0f,-1.0f, 1.0f); // Front Left Side Bottom + + glColor3f( 1.0f, 1.0f, 0.0f); + glVertex3f(-1.0f, 1.0f, 1.0f); // Front Left Side Top + + glColor3f( 1.0f, 1.0f, 1.0f); + glVertex3f( 1.0f, 1.0f, 1.0f); // Front Right Side Top + + + /* --- Bottom --- */ + glColor3f( 0.0f, 0.0f, 0.0f); + glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Back + + glColor3f( 0.0f, 0.0f, 1.0f); + glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Back + + glColor3f( 0.0f, 1.0f, 1.0f); + glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Right Front + + glColor3f( 0.0f, 1.0f, 0.0f); + glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Left Front + + glEnd(); // done with the polygon + + // swap buffers to display, since we're double buffered. + glutSwapBuffers(); +} + +void rota() +{ + glClear(GL_COLOR_BUFFER_BIT); + glRotatef(5,1,0.5,0.8); + DrawGLScene(); + glFlush(); + glutTimerFunc(10.0, &rota, 5); +} + +/* The function called whenever a key is pressed. */ +void keyPressed(unsigned char key, int x, int y) +{ + /* avoid thrashing this procedure */ + usleep(100); + + switch (key) + { + case 'f': glutFullScreen(); + break; + case 'w': glutReshapeWindow(640,480); + break; + case 27: glutDestroyWindow(window); + exit(0); + default: + break; + } +} + +void specialKeyPressed(int key, int x, int y) +{ + /* avoid thrashing this procedure */ + usleep(100); + + switch (key) + { + case GLUT_KEY_UP: + xrot += 10; + break; + case GLUT_KEY_DOWN: + xrot -= 10; + break; + case GLUT_KEY_LEFT: + yrot += 10; + break; + case GLUT_KEY_RIGHT: + yrot -= 10; + break; + default: + break; + } +} + +int main(int argc, char **argv) +{ + /* Initialize GLUT state - glut will take any command line arguments that pertain to it or + X Windows - look at its documentation at http://reality.sgi.com/mjk/spec3/spec3.html */ + glutInit(&argc, argv); + + /* Select type of Display mode: + Double buffer + RGBA color + Alpha components supported + Depth buffer */ + glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH); + + /* get a 640 x 480 window */ + glutInitWindowSize(640, 480); + + /* the window starts at the upper left corner of the screen */ + glutInitWindowPosition(0, 0); + + /* Open a window */ + window = glutCreateWindow("Jeff Molofee's GL Code Tutorial ... NeHe '99"); + + /* Register the function to do all our OpenGL drawing. */ + glutDisplayFunc(&DrawGLScene); + + /* Go fullscreen. This is the soonest we could possibly go fullscreen. */ + /*glutFullScreen();*/ + + /* Even if there are no events, redraw our gl scene. */ + glutIdleFunc(&DrawGLScene); + + /* Register the function called when our window is resized. */ + glutReshapeFunc(&ReSizeGLScene); + + /* Register the function called when the keyboard is pressed. */ + glutKeyboardFunc(&keyPressed); + + glutSpecialFunc(&specialKeyPressed); + + /* Initialize our window. */ + InitGL(640, 480); + + /* Start Event Processing Engine */ + glutMainLoop(); + + return 1; +} From e5e9fa0ede6e6f9b55d134468112a0b2209cfb6f Mon Sep 17 00:00:00 2001 From: eri451 Date: Tue, 21 Jan 2014 07:27:48 +0100 Subject: [PATCH 2/8] makefile --- lesson02/makefile | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 lesson02/makefile diff --git a/lesson02/makefile b/lesson02/makefile new file mode 100755 index 0000000..df89f9b --- /dev/null +++ b/lesson02/makefile @@ -0,0 +1,48 @@ +INCLUDE = -I/usr/include/ +LIBDIR = -L/usr/X11R6/lib + +COMPILERFLAGS = -Wall +CC = gcc +CFLAGS = $(COMPILERFLAGS) $(INCLUDE) +LIBRARIES = -lX11 -lXi -lXmu -lglut -lGL -lGLU -lm + +# for all, set the targets to be every lesson1.c-lesson13.c +# file, removing the .c extension. That is, at this point, +# it would produce lesson1, lesson2, lesson3,...,lesson13 targets. +# +all: $(basename $(wildcard lesson[1-9].c lesson1[0-3].c)) + +# same as for all, except set the targets to be +# lessonX.tar.gz from lessonX.c. This is really +# only used to build smaller tutorial .tar.gz files +# to send to nehe. +# +dist: $(foreach file,$(basename $(wildcard lesson[1-9].c lesson1[0-3].c)),$(file).tar.gz) + +# to produce, say, lesson1.tar.gz: +# +# 1. remove lesson1.tar.gz +# 2. build lesson1.tar containing README, makefile, lesson1.c, Data/lesson1/*. +# 3. gzip lesson1.tar. +# +lesson%.tar.gz : + tar cvf $(subst .tar.gz,.tar,$@) README makefile $(subst .tar.gz,.c,$@) $(wildcard Data/$(subst .tar.gz,,$@)/*); \ + gzip $(subst .tar.gz,.tar,$@); + +# to produce, say, lesson1: +# +# 1. compile the thing. uses the variables defined above. +# +lesson% : lesson%.o + $(CC) $(CFLAGS) -o $@ $(LIBDIR) $< $(LIBRARIES) + +# to clean up: +# delete all of the lessonX files. +clean: + rm $(wildcard lesson[1-9] lesson1[0-3]) + +# to clean up the distributions: +# delete all of the lessonX.tar.gz files. +distclean: + rm $(wildcard lesson[1-9].tar.gz lesson1[0-3].tar.gz) + From 0c088e247c6342f7a375ff5b7fe90ebbd95a43c9 Mon Sep 17 00:00:00 2001 From: eri451 Date: Tue, 21 Jan 2014 07:36:53 +0100 Subject: [PATCH 3/8] README --- README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..4d0d06d --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# GL learning with NeHe Tutorial + +it's more fun then it looks From c6434642e955c1ee11b4ca6de3b109ce124a5030 Mon Sep 17 00:00:00 2001 From: eri451 Date: Fri, 24 Jan 2014 11:23:49 +0100 Subject: [PATCH 4/8] multiple stuff is turning --- lesson02/lesson2.c | 370 ++++++++++++++++++++++++++++++++------------- 1 file changed, 264 insertions(+), 106 deletions(-) diff --git a/lesson02/lesson2.c b/lesson02/lesson2.c index fe263f2..18950c5 100755 --- a/lesson02/lesson2.c +++ b/lesson02/lesson2.c @@ -12,25 +12,152 @@ #include // Header File For sleeping. #include +#include + +#define PI 3.1415 /* ASCII code for the escape key. */ #define ESCAPE 27 -#define PAGE_UP 73 -#define PAGE_DOWN 81 -#define UP_ARROW 72 -#define DOWN_ARROW 80 -#define LEFT_ARROW 75 -#define RIGHT_ARROW 77 /* The number of our GLUT window */ int window; float xrot = 0.0f; float yrot = 0.0f; +float zrot = 0.0f; + +float i = 0.15; +int full = 0; +int oszi = 0; + +GLuint texture[1]; // Stores one new Texture + +struct Image { + unsigned long sizeX; + unsigned long sizeY; + char *data; +}; +typedef struct Image Image; + +int ImageLoad(char *filename, Image *image) { + FILE *file; + unsigned long size; // size of the image in bytes. + unsigned long i; // standard counter. + unsigned short int planes; // number of planes in image (must be 1) + unsigned short int bpp; // number of bits per pixel (must be 24) + char temp1; // temporary color storage for bgr-rgb conversion. + char temp2; + char temp3; + + // make sure the file is there. + if ((file = fopen(filename, "rb"))==NULL) + { + printf("File Not Found : %s\n",filename); + return 0; + } + + // seek through the bmp header, up to the width/height: + fseek(file, 18, SEEK_CUR); + + // read the width + if ((i = fread(&image->sizeX, 4, 1, file)) != 1) { + printf("Error reading width from %s.\n", filename); + return 0; + } + printf("Width of %s: %lu\n", filename, image->sizeX); + + // read the height + if ((i = fread(&image->sizeY, 4, 1, file)) != 1) { + printf("Error reading height from %s.\n", filename); + return 0; + } + printf("Height of %s: %lu\n", filename, image->sizeY); + + // calculate the size (assuming 24 bits or 3 bytes per pixel). + size = image->sizeX * image->sizeY * 3; + + // read the planes + if ((fread(&planes, 2, 1, file)) != 1) { + printf("Error reading planes from %s.\n", filename); + return 0; + } + if (planes != 1) { + printf("Planes from %s is not 1: %u\n", filename, planes); + return 0; + } + + // read the bpp + if ((i = fread(&bpp, 2, 1, file)) != 1) { + printf("Error reading bpp from %s.\n", filename); + return 0; + } + if (bpp != 24) { + printf("Bpp from %s is not 24: %u\n", filename, bpp); + return 0; + } + + // seek past the rest of the bitmap header. + fseek(file, 24, SEEK_CUR); + + // read the data. + image->data = (char *) malloc(size); + if (image->data == NULL) { + printf("Error allocating memory for color-corrected image data"); + return 0; + } + + if ((i = fread(image->data, size, 1, file)) != 1) { + printf("Error reading image data from %s.\n", filename); + return 0; + } + + for (i=0;i rgb) + temp1 = image->data[ i ]; // b -- don't ask its what gimp gave me + temp2 = image->data[i+1]; // r + temp3 = image->data[i+2]; // g + + image->data[i] = temp2; + image->data[i+1] = temp1; + image->data[i+2] = temp3; + } + + // we're done. + return 1; +} + +// Load Bitmaps And Convert To Textures +void LoadGLTextures() { + // Load Texture + Image *image1; + + // allocate space for texture + image1 = (Image *) malloc(sizeof(Image)); + if (image1 == NULL) { + printf("Error allocating space for image"); + exit(0); + } + + if (!ImageLoad("/home/eri/Bilder/texturefun1.bmp", image1)) { + exit(1); + } + + // Create Texture + glGenTextures(1, &texture[0]); + glBindTexture(GL_TEXTURE_2D, texture[0]); // 2d texture (x and y size) + + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // scale linearly when image bigger than texture + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // scale linearly when image smalled than texture + + // 2d texture, level of detail 0 (normal), 3 components (red, green, blue), x size from image, y size from image, + // border 0 (normal), rgb color data, unsigned byte data, and finally the data itself. + glTexImage2D(GL_TEXTURE_2D, 0, 3, image1->sizeX, image1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image1->data); +}; /* A general OpenGL initialization function. Sets all of the initial parameters. */ void InitGL(int Width, int Height) // We call this right after our OpenGL window is created. { + LoadGLTextures(); // Load The Texture(s) + glEnable(GL_TEXTURE_2D); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black glClearDepth(1.0); // Enables Clearing Of The Depth Buffer glDepthFunc(GL_LESS); // The Type Of Depth Test To Do @@ -61,6 +188,99 @@ void ReSizeGLScene(int Width, int Height) glMatrixMode(GL_MODELVIEW); } +void rota(int what) +{ + usleep(10); + switch(what) + { + case 0: + xrot += i; + break; + case 1: + yrot += i; + break; + case 2: + zrot += i; + break; + default: + xrot += i; + yrot += i; + zrot += i; + } + if (xrot > 360) xrot = 0; + if (yrot > 360) yrot = 0; + if (zrot > 360) zrot = 0; +} + +void DrawBracket(float i){ + // draw a square (quadrilateral) + glBegin(GL_QUADS); // start drawing a polygon (4 sided) + + // Down + // Front Face (note that the texture's corners have to match the quad's corners) + glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f + i, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.7f + i, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.9f + i, 0.0f, 0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.2f + i, 0.0f, 0.5f); // Top Left Of The Texture and Quad + + // Back Face + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.7f + i, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.9f + i, 0.0f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.2f + i, 0.0f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f + i, -0.5f, -0.5f); // Bottom Left Of The Texture and Quad + + // Bottom Face + glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f + i, -0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.7f + i, -0.5f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.7f + i, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f + i, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad + + // Right face + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.7f + i, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.9f + i, 0.0f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.9f + i, 0.0f, 0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.7f + i, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + + // Left Face + glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f + i, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f + i, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.2f + i, 0.0f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.2f + i, 0.0f, 0.5f); // Top Left Of The Texture and Quad + + // Up + // Front Face (note that the texture's corners have to match the quad's corners) + glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.2f + i, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.9f + i, 0.0f, 0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.7f + i, 0.5f, 0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f + i, 0.5f, 0.5f); // Top Left Of The Texture and Quad + + // Back Face + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.9f + i, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.7f + i, 0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f + i, 0.5f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.2f + i, 0.0f, -0.5f); // Bottom Left Of The Texture and Quad + + // Top Face + glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f + i, 0.5f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f + i, 0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.7f + i, 0.5f, 0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.7f + i, 0.5f, -0.5f); // Top Right Of The Texture and Quad + + // Left Face + glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.2f + i, -0.0f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f + i, 0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f + i, 0.5f, 0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.2f + i, -0.0f, 0.5f); // Bottom Left Of The Texture and Quad + + // Right face + glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.9f + i, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.9f + i, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.7f + i, 0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.7f + i, 0.5f, 0.5f); // Top Left Of The Texture and Quad + + glEnd(); // done with the polygon +} + /* The main drawing function. */ void DrawGLScene() { @@ -72,106 +292,21 @@ void DrawGLScene() glRotatef(xrot, 1.0f, 0.0f, 0.0f); glRotatef(yrot, 0.0f, 1.0f, 0.0f); + glRotatef(zrot, 0.0f, 0.0f, 1.0f); - // draw a square (quadrilateral) - glBegin(GL_QUADS); // start drawing a polygon (4 sided) - - /* --- Top --- */ - glColor3f( 1.0f, 1.0f, 0.0f); - glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Front - - glColor3f( 1.0f, 1.0f, 1.0f); - glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Front - - glColor3f( 1.0f, 0.0f, 1.0f); - glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Back - - glColor3f( 1.0f, 0.0f, 0.0f); - glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Back - - - /* --- Left Side --- */ - glColor3f( 0.0f, 0.0f, 0.0f); - glVertex3f(-1.0f,-1.0f,-1.0f); // Left Side Bottom Back - - glColor3f( 0.0f, 1.0f, 0.0f); - glVertex3f(-1.0f,-1.0f, 1.0f); // Left Side Bottom Front - - glColor3f( 1.0f, 1.0f, 0.0f); - glVertex3f(-1.0f, 1.0f, 1.0f); // Left Side Top Front - - glColor3f( 1.0f, 0.0f, 0.0f); - glVertex3f(-1.0f, 1.0f,-1.0f); // Left Side Top Back - - - /* --- Right Side --- */ - glColor3f( 0.0f, 0.0f, 1.0f); - glVertex3f( 1.0f,-1.0f,-1.0f); // Right Side Bottom Back - - glColor3f( 0.0f, 1.0f, 1.0f); - glVertex3f( 1.0f,-1.0f, 1.0f); // Right Side Bottom Front - - glColor3f( 1.0f, 1.0f, 1.0f); - glVertex3f( 1.0f, 1.0f, 1.0f); // Right Side Top Front - - glColor3f( 1.0f, 0.0f, 1.0f); - glVertex3f( 1.0f, 1.0f,-1.0f); // Right Side Top Back - - - /* --- Back Side --- */ - glColor3f( 0.0f, 0.0f, 1.0f); - glVertex3f( 1.0f,-1.0f,-1.0f); // Back Right Side Bottom + glBindTexture(GL_TEXTURE_2D, texture[0]); // choose the texture to use. - glColor3f( 0.0f, 0.0f, 0.0f); - glVertex3f(-1.0f,-1.0f,-1.0f); // Back Left Side Bottom + DrawBracket(0); - glColor3f( 1.0f, 0.0f, 0.0f); - glVertex3f(-1.0f, 1.0f,-1.0f); // Back Left Side Top - - glColor3f( 1.0f, 0.0f, 1.0f); - glVertex3f( 1.0f, 1.0f,-1.0f); // Back Right Side Top - - - /* --- Front --- */ - glColor3f( 0.0f, 1.0f, 1.0f); - glVertex3f( 1.0f,-1.0f, 1.0f); // Front Right Side Bottom - - glColor3f( 0.0f, 1.0f, 0.0f); - glVertex3f(-1.0f,-1.0f, 1.0f); // Front Left Side Bottom - - glColor3f( 1.0f, 1.0f, 0.0f); - glVertex3f(-1.0f, 1.0f, 1.0f); // Front Left Side Top - - glColor3f( 1.0f, 1.0f, 1.0f); - glVertex3f( 1.0f, 1.0f, 1.0f); // Front Right Side Top - - - /* --- Bottom --- */ - glColor3f( 0.0f, 0.0f, 0.0f); - glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Back - - glColor3f( 0.0f, 0.0f, 1.0f); - glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Back - - glColor3f( 0.0f, 1.0f, 1.0f); - glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Right Front - - glColor3f( 0.0f, 1.0f, 0.0f); - glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Left Front + glRotatef(xrot, 1.0f, 0.0f, 0.0f); + DrawBracket(0.7); - glEnd(); // done with the polygon + glRotatef(xrot, 1.0f, 0.0f, 0.0f); + DrawBracket(1.4); // swap buffers to display, since we're double buffered. glutSwapBuffers(); -} - -void rota() -{ - glClear(GL_COLOR_BUFFER_BIT); - glRotatef(5,1,0.5,0.8); - DrawGLScene(); - glFlush(); - glutTimerFunc(10.0, &rota, 5); + if (oszi) rota(0); } /* The function called whenever a key is pressed. */ @@ -182,10 +317,29 @@ void keyPressed(unsigned char key, int x, int y) switch (key) { - case 'f': glutFullScreen(); + case 'f': if (!full) + { + glutFullScreen(); + full = 1; + } else { + glutReshapeWindow(640,480); + full = 0; + } break; - case 'w': glutReshapeWindow(640,480); + + case 'm': if (!oszi) + { + oszi = 1; + } else { + oszi = 0; + } break; + + case ' ': + zrot += 5; + break; + + case '0': zrot = xrot = yrot = 0; break; case 27: glutDestroyWindow(window); exit(0); default: @@ -201,16 +355,20 @@ void specialKeyPressed(int key, int x, int y) switch (key) { case GLUT_KEY_UP: - xrot += 10; + xrot += 5; + oszi = 0; break; case GLUT_KEY_DOWN: - xrot -= 10; + xrot -= 5; + oszi = 0; break; case GLUT_KEY_LEFT: - yrot += 10; + yrot += 5; + oszi = 0; break; case GLUT_KEY_RIGHT: - yrot -= 10; + yrot -= 5; + oszi = 0; break; default: break; @@ -234,7 +392,7 @@ int main(int argc, char **argv) glutInitWindowSize(640, 480); /* the window starts at the upper left corner of the screen */ - glutInitWindowPosition(0, 0); + glutInitWindowPosition(400, 210); /* Open a window */ window = glutCreateWindow("Jeff Molofee's GL Code Tutorial ... NeHe '99"); From a23c5b015929d60efca15657dc52bd9e932a3468 Mon Sep 17 00:00:00 2001 From: eri451 Date: Fri, 24 Jan 2014 12:33:49 +0100 Subject: [PATCH 5/8] c3d2 rotating yay --- lesson02/lesson2.c | 264 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 212 insertions(+), 52 deletions(-) diff --git a/lesson02/lesson2.c b/lesson02/lesson2.c index 18950c5..cc1ae87 100755 --- a/lesson02/lesson2.c +++ b/lesson02/lesson2.c @@ -207,76 +207,214 @@ void rota(int what) yrot += i; zrot += i; } - if (xrot > 360) xrot = 0; - if (yrot > 360) yrot = 0; - if (zrot > 360) zrot = 0; + if (xrot > 360) { xrot = 0; oszi = 0;} + if (yrot > 360) { yrot = 0; oszi = 0;} + if (zrot > 360) { zrot = 0; oszi = 0;} } -void DrawBracket(float i){ +void DrawOpenBracket(){ // draw a square (quadrilateral) glBegin(GL_QUADS); // start drawing a polygon (4 sided) // Down // Front Face (note that the texture's corners have to match the quad's corners) - glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f + i, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.7f + i, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.9f + i, 0.0f, 0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.2f + i, 0.0f, 0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.4f, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad // Back Face - glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.7f + i, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.9f + i, 0.0f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.2f + i, 0.0f, -0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f + i, -0.5f, -0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.4f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Bottom Left Of The Texture and Quad // Bottom Face - glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f + i, -0.5f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.7f + i, -0.5f, -0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.7f + i, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f + i, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.4f, -0.5f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.4f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad // Right face - glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.7f + i, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.9f + i, 0.0f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.9f + i, 0.0f, 0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.7f + i, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.4f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.4f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad // Left Face - glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f + i, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f + i, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.2f + i, 0.0f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.2f + i, 0.0f, 0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad // Up // Front Face (note that the texture's corners have to match the quad's corners) - glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.2f + i, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.9f + i, 0.0f, 0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.7f + i, 0.5f, 0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f + i, 0.5f, 0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.4f, 0.5f, 0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Top Left Of The Texture and Quad // Back Face - glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.9f + i, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.7f + i, 0.5f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f + i, 0.5f, -0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.2f + i, 0.0f, -0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Bottom Left Of The Texture and Quad // Top Face - glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f + i, 0.5f, -0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f + i, 0.5f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.7f + i, 0.5f, 0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.7f + i, 0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.4f, 0.5f, 0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad // Left Face - glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.2f + i, -0.0f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f + i, 0.5f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f + i, 0.5f, 0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.2f + i, -0.0f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.2f, -0.0f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.2f, -0.0f, 0.5f); // Bottom Left Of The Texture and Quad // Right face - glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.9f + i, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.9f + i, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.7f + i, 0.5f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.7f + i, 0.5f, 0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.4f, 0.5f, 0.5f); // Top Left Of The Texture and Quad + + glEnd(); // done with the polygon +} + +void DrawCloseBracket(){ + // draw a square (quadrilateral) + glBegin(GL_QUADS); // start drawing a polygon (4 sided) + + // Down + // Front Face (note that the texture's corners have to match the quad's corners) + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad + + // Back Face + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Bottom Left Of The Texture and Quad + + // Bottom Face + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.4f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad + + // Right face + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.4f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + + // Left Face + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad + + // Up + // Front Face (note that the texture's corners have to match the quad's corners) + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.4f, 0.5f, 0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Top Left Of The Texture and Quad + + // Back Face + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Bottom Left Of The Texture and Quad + + // Top Face + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.4f, 0.5f, 0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad + + // Left Face + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.2f, -0.0f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.2f, -0.0f, 0.5f); // Bottom Left Of The Texture and Quad + + // Right face + glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.4f, 0.5f, 0.5f); // Top Left Of The Texture and Quad + + glEnd(); // done with the polygon +} + +void DrawSlash(){ + // draw a square (quadrilateral) + glBegin(GL_QUADS); // start drawing a polygon (4 sided) + + // Down + // Front Face (note that the texture's corners have to match the quad's corners) + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad + + // Back Face + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Bottom Left Of The Texture and Quad + + // Bottom Face + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.4f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad + + // Right face + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.4f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + + // Left Face + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad + + // Up + // Front Face (note that the texture's corners have to match the quad's corners) + glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.4f, 0.5f, 0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Top Left Of The Texture and Quad + + // Back Face + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Bottom Left Of The Texture and Quad + + // Top Face + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.4f, 0.5f, 0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad + + // Left Face + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad + + // Right face + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.4f, 0.5f, 0.5f); // Top Left Of The Texture and Quad glEnd(); // done with the polygon } @@ -288,7 +426,7 @@ void DrawGLScene() glLoadIdentity(); // Reset The View - glTranslatef(0.0f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0 + glTranslatef(0.0f,0.0f,-8.0f); // Move Left 1.5 Units And Into The Screen 6.0 glRotatef(xrot, 1.0f, 0.0f, 0.0f); glRotatef(yrot, 0.0f, 1.0f, 0.0f); @@ -296,13 +434,35 @@ void DrawGLScene() glBindTexture(GL_TEXTURE_2D, texture[0]); // choose the texture to use. - DrawBracket(0); - - glRotatef(xrot, 1.0f, 0.0f, 0.0f); - DrawBracket(0.7); - - glRotatef(xrot, 1.0f, 0.0f, 0.0f); - DrawBracket(1.4); + glTranslatef(-3.0f, 0.0f, 0.0f); + glRotatef(xrot, 0.0f, 1.0f, 0.0f); + DrawOpenBracket(); + glRotatef(xrot, 0.0f,-1.0f, 0.0f); + + glTranslatef(1.2f, 0.0f, 0.0f); + glRotatef(xrot, 0.0f, 1.0f, 0.0f); + DrawOpenBracket(); + glRotatef(xrot, 0.0f,-1.0f, 0.0f); + + glTranslatef(1.2f, 0.0f, 0.0f); + glRotatef(xrot, 0.0f, 1.0f, 0.0f); + DrawOpenBracket(); + glRotatef(xrot, 0.0f,-1.0f, 0.0f); + + glTranslatef(1.2f, 0.0f, 0.0f); + glRotatef(xrot, 0.0f, 0.0f, 1.0f); + DrawSlash(); + glRotatef(xrot, 0.0f, 0.0f,-1.0f); + + glTranslatef(1.2f, 0.0f, 0.0f); + glRotatef(xrot, 0.0f, 1.0f, 0.0f); + DrawCloseBracket(); + glRotatef(xrot, 0.0f,-1.0f, 0.0f); + + glTranslatef(1.2f, 0.0f, 0.0f); + glRotatef(xrot, 0.0f, 1.0f, 0.0f); + DrawCloseBracket(); + glRotatef(xrot, 0.0f,-1.0f, 0.0f); // swap buffers to display, since we're double buffered. glutSwapBuffers(); From 23b7783dd6dbefeffcfd8fe6d0b194e3e9964d84 Mon Sep 17 00:00:00 2001 From: eri451 Date: Fri, 24 Jan 2014 13:48:12 +0100 Subject: [PATCH 6/8] forgot the texture --- lesson02/lesson2.c | 4 ++-- lesson02/texture.bmp | Bin 0 -> 196730 bytes 2 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 lesson02/texture.bmp diff --git a/lesson02/lesson2.c b/lesson02/lesson2.c index cc1ae87..339663f 100755 --- a/lesson02/lesson2.c +++ b/lesson02/lesson2.c @@ -137,7 +137,7 @@ void LoadGLTextures() { exit(0); } - if (!ImageLoad("/home/eri/Bilder/texturefun1.bmp", image1)) { + if (!ImageLoad("texture.bmp", image1)) { exit(1); } @@ -158,7 +158,7 @@ void InitGL(int Width, int Height) // We call this right after our OpenG { LoadGLTextures(); // Load The Texture(s) glEnable(GL_TEXTURE_2D); - glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black + glClearColor(0.2f, 0.2f, 0.2f, 0.0f); // This Will Clear The Background Color To Black glClearDepth(1.0); // Enables Clearing Of The Depth Buffer glDepthFunc(GL_LESS); // The Type Of Depth Test To Do glEnable(GL_DEPTH_TEST); // Enables Depth Testing diff --git a/lesson02/texture.bmp b/lesson02/texture.bmp new file mode 100644 index 0000000000000000000000000000000000000000..59143707f897dcc17c96cc24f47978cbbd02354d GIT binary patch literal 196730 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 Tfd412@9dTTw;X>FIFrCH8FsMw literal 0 HcmV?d00001 From 930291bd672cb60b68c1f5637decdc4ec00c032e Mon Sep 17 00:00:00 2001 From: eri451 Date: Sat, 25 Jan 2014 15:50:46 +0100 Subject: [PATCH 7/8] eppic fail Chris --- lesson02/lesson2.c | 181 +++++------------------------------------ lesson02/makefile | 7 +- lesson02/openBracket.c | 85 +++++++++++++++++++ lesson02/openBracket.h | 11 +++ lesson02/slash.c | 86 ++++++++++++++++++++ lesson02/slash.h | 11 +++ lesson02/texture.bmp | Bin 196730 -> 196730 bytes 7 files changed, 220 insertions(+), 161 deletions(-) create mode 100644 lesson02/openBracket.c create mode 100644 lesson02/openBracket.h create mode 100644 lesson02/slash.c create mode 100644 lesson02/slash.h diff --git a/lesson02/lesson2.c b/lesson02/lesson2.c index 339663f..d88a005 100755 --- a/lesson02/lesson2.c +++ b/lesson02/lesson2.c @@ -10,10 +10,14 @@ #include // Header File For The OpenGL32 Library #include // Header File For The GLu32 Library #include // Header File For sleeping. +#include // Header File for math. #include #include +#include "slash.h" +#include "openBracket.h" + #define PI 3.1415 /* ASCII code for the escape key. */ @@ -26,7 +30,7 @@ float xrot = 0.0f; float yrot = 0.0f; float zrot = 0.0f; -float i = 0.15; +float i = 0.3; int full = 0; int oszi = 0; @@ -207,79 +211,11 @@ void rota(int what) yrot += i; zrot += i; } - if (xrot > 360) { xrot = 0; oszi = 0;} - if (yrot > 360) { yrot = 0; oszi = 0;} - if (zrot > 360) { zrot = 0; oszi = 0;} + if (xrot >= 360) xrot = 0; + if (yrot >= 360) yrot = 0; + if (zrot >= 360) zrot = 0; } -void DrawOpenBracket(){ - // draw a square (quadrilateral) - glBegin(GL_QUADS); // start drawing a polygon (4 sided) - - // Down - // Front Face (note that the texture's corners have to match the quad's corners) - glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.4f, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad - - // Back Face - glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.4f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Bottom Left Of The Texture and Quad - - // Bottom Face - glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.4f, -0.5f, -0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.4f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad - - // Right face - glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.4f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.4f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad - - // Left Face - glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad - - // Up - // Front Face (note that the texture's corners have to match the quad's corners) - glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.4f, 0.5f, 0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Top Left Of The Texture and Quad - - // Back Face - glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Bottom Left Of The Texture and Quad - - // Top Face - glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.4f, 0.5f, 0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad - - // Left Face - glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.2f, -0.0f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.2f, -0.0f, 0.5f); // Bottom Left Of The Texture and Quad - - // Right face - glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.4f, 0.5f, 0.5f); // Top Left Of The Texture and Quad - - glEnd(); // done with the polygon -} void DrawCloseBracket(){ // draw a square (quadrilateral) @@ -350,74 +286,6 @@ void DrawCloseBracket(){ glEnd(); // done with the polygon } -void DrawSlash(){ - // draw a square (quadrilateral) - glBegin(GL_QUADS); // start drawing a polygon (4 sided) - - // Down - // Front Face (note that the texture's corners have to match the quad's corners) - glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad - - // Back Face - glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Bottom Left Of The Texture and Quad - - // Bottom Face - glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, -0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.4f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad - - // Right face - glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.4f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad - - // Left Face - glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad - - // Up - // Front Face (note that the texture's corners have to match the quad's corners) - glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.4f, 0.5f, 0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Top Left Of The Texture and Quad - - // Back Face - glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Bottom Left Of The Texture and Quad - - // Top Face - glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.4f, 0.5f, 0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad - - // Left Face - glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad - - // Right face - glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.4f, 0.5f, 0.5f); // Top Left Of The Texture and Quad - - glEnd(); // done with the polygon -} /* The main drawing function. */ void DrawGLScene() @@ -429,44 +297,39 @@ void DrawGLScene() glTranslatef(0.0f,0.0f,-8.0f); // Move Left 1.5 Units And Into The Screen 6.0 glRotatef(xrot, 1.0f, 0.0f, 0.0f); - glRotatef(yrot, 0.0f, 1.0f, 0.0f); + glRotatef(yrot, 0.0f, 0.0f, 0.0f); glRotatef(zrot, 0.0f, 0.0f, 1.0f); + glTranslatef(0.0f, sin((yrot*PI)/180), 0.0f); + glBindTexture(GL_TEXTURE_2D, texture[0]); // choose the texture to use. glTranslatef(-3.0f, 0.0f, 0.0f); - glRotatef(xrot, 0.0f, 1.0f, 0.0f); - DrawOpenBracket(); - glRotatef(xrot, 0.0f,-1.0f, 0.0f); + DrawOpenBracket( 0.0f, yrot, 0.0f); glTranslatef(1.2f, 0.0f, 0.0f); - glRotatef(xrot, 0.0f, 1.0f, 0.0f); - DrawOpenBracket(); - glRotatef(xrot, 0.0f,-1.0f, 0.0f); + DrawOpenBracket( 0.0f, yrot, 0.0f); glTranslatef(1.2f, 0.0f, 0.0f); - glRotatef(xrot, 0.0f, 1.0f, 0.0f); - DrawOpenBracket(); - glRotatef(xrot, 0.0f,-1.0f, 0.0f); + DrawOpenBracket( 0.0f, yrot, 0.0f); glTranslatef(1.2f, 0.0f, 0.0f); - glRotatef(xrot, 0.0f, 0.0f, 1.0f); - DrawSlash(); - glRotatef(xrot, 0.0f, 0.0f,-1.0f); + DrawSlash(0.0f, yrot, 0.0f); glTranslatef(1.2f, 0.0f, 0.0f); - glRotatef(xrot, 0.0f, 1.0f, 0.0f); + glRotatef(yrot, 0.0f, 1.0f, 0.0f); DrawCloseBracket(); - glRotatef(xrot, 0.0f,-1.0f, 0.0f); + glRotatef(yrot, 0.0f,-1.0f, 0.0f); glTranslatef(1.2f, 0.0f, 0.0f); - glRotatef(xrot, 0.0f, 1.0f, 0.0f); + glRotatef(yrot, 0.0f, 1.0f, 0.0f); DrawCloseBracket(); - glRotatef(xrot, 0.0f,-1.0f, 0.0f); + glRotatef(yrot, 0.0f,-1.0f, 0.0f); + // swap buffers to display, since we're double buffered. glutSwapBuffers(); - if (oszi) rota(0); + if (oszi) rota(1); } /* The function called whenever a key is pressed. */ @@ -555,7 +418,7 @@ int main(int argc, char **argv) glutInitWindowPosition(400, 210); /* Open a window */ - window = glutCreateWindow("Jeff Molofee's GL Code Tutorial ... NeHe '99"); + window = glutCreateWindow("c3d2 animation"); /* Register the function to do all our OpenGL drawing. */ glutDisplayFunc(&DrawGLScene); diff --git a/lesson02/makefile b/lesson02/makefile index df89f9b..41b2245 100755 --- a/lesson02/makefile +++ b/lesson02/makefile @@ -5,6 +5,7 @@ COMPILERFLAGS = -Wall CC = gcc CFLAGS = $(COMPILERFLAGS) $(INCLUDE) LIBRARIES = -lX11 -lXi -lXmu -lglut -lGL -lGLU -lm +OBJECTS = $(patsubst %.c, %.o, $(wildcard ./*.c)) # for all, set the targets to be every lesson1.c-lesson13.c # file, removing the .c extension. That is, at this point, @@ -33,8 +34,8 @@ lesson%.tar.gz : # # 1. compile the thing. uses the variables defined above. # -lesson% : lesson%.o - $(CC) $(CFLAGS) -o $@ $(LIBDIR) $< $(LIBRARIES) +lesson% : lesson%.o $(OBJECTS) + $(CC) $(CFLAGS) -o $@ $(OBJECTS) $(LIBDIR) $(LIBRARIES) # to clean up: # delete all of the lessonX files. @@ -46,3 +47,5 @@ clean: distclean: rm $(wildcard lesson[1-9].tar.gz lesson1[0-3].tar.gz) +%.o: %.c + $(CC) -c -o $@ $< diff --git a/lesson02/openBracket.c b/lesson02/openBracket.c new file mode 100644 index 0000000..4845bc2 --- /dev/null +++ b/lesson02/openBracket.c @@ -0,0 +1,85 @@ +#include // Header File For The GLUT Library +#include // Header File For The OpenGL32 Library +#include // Header File For The GLu32 Library + + +void DrawOpenBracket(float xrot, float yrot, float zrot) +{ + glRotatef(xrot, 1.0f, 0.0f, 0.0f); + glRotatef(yrot, 0.0f, 1.0f, 0.0f); + glRotatef(zrot, 0.0f, 0.0f, 1.0f); + + // draw a square (quadrilateral) + glBegin(GL_QUADS); // start drawing a polygon (4 sided) + + // Down + // Front Face (note that the texture's corners have to match the quad's corners) + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.4f, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad + + // Back Face + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.4f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Bottom Left Of The Texture and Quad + + // Bottom Face + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.4f, -0.5f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.4f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad + + // Right face + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.4f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.4f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + + // Left Face + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad + + // Up + // Front Face (note that the texture's corners have to match the quad's corners) + glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.4f, 0.5f, 0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Top Left Of The Texture and Quad + + // Back Face + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Bottom Left Of The Texture and Quad + + // Top Face + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.4f, 0.5f, 0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad + + // Left Face + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.2f, -0.0f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.2f, -0.0f, 0.5f); // Bottom Left Of The Texture and Quad + + // Right face + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.4f, 0.5f, 0.5f); // Top Left Of The Texture and Quad + + glEnd(); // done with the polygon + + glRotatef(xrot,-1.0f, 0.0f, 0.0f); + glRotatef(yrot, 0.0f,-1.0f, 0.0f); + glRotatef(zrot, 0.0f, 0.0f,-1.0f); +} + +/* vim: set et sw=4 ts=4: */ + diff --git a/lesson02/openBracket.h b/lesson02/openBracket.h new file mode 100644 index 0000000..0ddccf9 --- /dev/null +++ b/lesson02/openBracket.h @@ -0,0 +1,11 @@ +#ifndef SLASH_H +#define SLASH_H + +/* + * Draw a textured 2 boxed sharp opening bracket + * rotate the object with the 3 args + */ + +void DrawOpenBracket(float xrot, float yrot, float zrot); + +#endif diff --git a/lesson02/slash.c b/lesson02/slash.c new file mode 100644 index 0000000..7260c2f --- /dev/null +++ b/lesson02/slash.c @@ -0,0 +1,86 @@ +#include // Header File For The GLUT Library +#include // Header File For The OpenGL32 Library +#include // Header File For The GLu32 Library + + +void DrawSlash(float xrot, float yrot, float zrot){ + + glRotatef(xrot, 1.0f, 0.0f, 0.0f); + glRotatef(yrot, 0.0f, 1.0f, 0.0f); + glRotatef(zrot, 0.0f, 0.0f, 1.0f); + + // draw a square (quadrilateral) + glBegin(GL_QUADS); // start drawing a polygon (4 sided) + + // Down + // Front Face (note that the texture's corners have to match the quad's corners) + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad + + // Back Face + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Bottom Left Of The Texture and Quad + + // Bottom Face + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.4f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad + + // Right face + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.4f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + + // Left Face + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad + + // Up + // Front Face (note that the texture's corners have to match the quad's corners) + glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.4f, 0.5f, 0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Top Left Of The Texture and Quad + + // Back Face + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Bottom Left Of The Texture and Quad + + // Top Face + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.4f, 0.5f, 0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad + + // Left Face + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad + + // Right face + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.4f, 0.5f, 0.5f); // Top Left Of The Texture and Quad + + glEnd(); // done with the polygon + + + glRotatef(xrot,-1.0f, 0.0f, 0.0f); + glRotatef(yrot, 0.0f,-1.0f, 0.0f); + glRotatef(zrot, 0.0f, 0.0f,-1.0f); +} + +/* vim: set et sw=4 ts=4: */ + diff --git a/lesson02/slash.h b/lesson02/slash.h new file mode 100644 index 0000000..61f10e1 --- /dev/null +++ b/lesson02/slash.h @@ -0,0 +1,11 @@ +#ifndef SLASH_H +#define SLASH_H + +/* + * Draw a textured 2 boxed slash + * rotate the object with the 3 args + */ + +void DrawSlash(float xrot, float yrot, float zrot); + +#endif diff --git a/lesson02/texture.bmp b/lesson02/texture.bmp index 59143707f897dcc17c96cc24f47978cbbd02354d..89184101b39154467ce0bd8369b54cc3863a3ff4 100644 GIT binary patch literal 196730 zcmeI5JCYp95kzOXB1I~^1@5p4B`Q3{3e>3Wd2ml~2A`Ul>dNX&kDo`Cj{%12?2O3B z=dTAa*na-__g^o+zr20@_4@O_Zx6ry`1#w*Ki^)xe*OOPkH5cs|M}zf%gZ1C`p^G< zJ~K)~iFw^&by4YZ}&o z(*H+*jaIzWwfEtH7N)PcF`xfDsR5JNrS<9n3?Elw)-1%GxfnAguZCt#!x|9y?*+M}kC(dkJ|)+mJTy#SbK`3NCjoM9vrFsMfs@ZRm08oU2BrRQ zd^$dOscY}UPcKYgbK^Sy`BOWY&@Qc4hm#?B-ZE<%)}Y9Lo@jtcywtV#0fsLr3Deiy zxWfOE2)qupOY7Ca>qZHE%$kNZNcTU1cH9wO>e~Cn-7%tbn7-!5x&BA6P3viw)~iF> zmAwu!YZ}%d(SI+PC4Icqwf8BxzVXm7ea(%t{5JxuEw@YS)uEOHe7afFum&mq!`v7O zz0|e$VW5G{5T>uWalHQ+F_J2~v|b%ZfM8>oH4SSJ>_3K!q{>TOdmj=Y*cflur~Qib zAHzjbWtY~g0|^jpjGqwh=Rbyvq{>TOdmj=Y*ck8EznT9SE|RME)FOX#oH>OA2sXy2 z3*O0p3>Qh&r_@UQCjo+uvB!8D|1n%7Rr}QH{3ii|jd6hS9{yvvNU9D}EApQN2sXws z#vAyL;UcLzPOZX!5+K+ZLyTAVAHzjbHB2qte-a?r7-twS?LUT#r0OiST>nXcU}HSN zcwPT7TqIRbQcLuo1PC_9bBq`DAHzjb^*psK|4D#gV@zSZqW>5!lB%iHQv4?Yf{ihY z@pArSxJasIQ;YYX1PC_90>*3kkKrPzT1YL}e-a?r7;6|WQh2e`=`zBtWn+LNIplAHzjb z6_Og{KM4?Qj3|us{$sdEs-jX`_n!m^Hbx*uZvQb{BvpZ_E&5La1REn3BeDM&E|RL) z)K>f_0fLPYj*-=W3>QgNcxu!BlK{cS$iOK7zkb2e8C7MZHs}9n!WQdE80EjK|4FG$ z_}@bE(U5r<<-ec*d8s|~f8e{X!~g8m#{Q4IYO!8` zQU06#FGy|Re+$V+L)KuF|2F??Qakd0;BiL_RIf~S1r~lFv|Z$|0z=Y?tcr(M?aOKv!wRtw~<#Z)_E|p>i(@NboSi(W<=i*u6dsH}Cz1aX zfBxY~ElA6pwmcZ$Cz1cp{C{Wl>u+7ER&p#2I;9HQlXK<&ssB&tC4M4;w9IMCgKf5AWhunI7Ae}bh!M}%VWYQEiF{{Q?wQ1Qo`QJPyi?H)!qqFVn*RsO%y zpiSpvQvA}0*Uj-Pt|1q5|E1_7tnjgZvv;SUT zUHTlR(_+!(`q52BBya0~H1MVVqjdP!m#$g0`2^!V{jUn*@Z6Jh$lp4=4%^~6!yEcf z70`J)%sksA5yAX1k&Ltse(3tF2?G@{?DUJ*omb>QkB5RcmxdUs{R{! z`j*4#FckWti0EdabV>gsAj3T^>6F*Pw@xcGBD$XcY2;@PGNw~oK6Am^J$619^S?HZ z-Rbsp3OnrXLio}J&XxS9%E%?1swPw<4~Ow0a~b~+DOD|crBl+U3fla+j##eY|2(>c zosQ|`w@Tn+Ji?dB1^hSi^ey*IC%Kz1iimFRK)U-M0U7S;o=#>%_||EK5j0x+pGJP> zponzRdd^(1c25wBzW&$7u{%8|ot(D2yAZyN7Xvh}p34Dx4Bw%FK|MSi2|U)}x*+{I88;clwBAi}l@I z2wx^+`TX0W56GYtOI7 z@NPXK+7AH1|B$yl9m@a=dY{i=xt&)nt^Vie65jP9T+%0jkMW2SERToE|HB*~K{Z-A zyb;wR4@~+0Cl1^C?U%>D|BhiHsiJj$8;k@LHpb6eT-SdL z3rW@H80`ZIC~S;(su%Si!$MN^o{q8lB%VI}Yj_*_k6|IHT1%(Ge-cpG7|VFO`Hx{Csaj4a-G35L*cb@jR{mpH zNUD%@a{VU(g^dB??c+a&g`^5hC((ZrP}mqa-X{KISV*eybh7*>0fmiW!rQ@r3=2t> zDV-GmNkCy^Sn<;Pk6|IHvZfR7KM5#o3FRT9;7LqErbi({60fmj>iC6xA{eq=1s`5-H#{bdeE!Lg!%70h?ozn^M zzlG$ZA^q{ne?R~I)A9CyWn$`Dn-}yz<|}|EP5Q{2zJMVm%PA z{5Sg_n2wYGEhHZe8H-o`+x(AB$HV`TS1s1V@ydUL|KaJF{cj=pXvhq_@*nj-BOROn zBd=PlC*hUIR z75}r-S@(bBRg3ikyz+nA|AKTD{cj=pXviA8@_)|%nsiqDA9>Ycy$rAXpYXpdooWAD zNIn{}60iJ!=6_{6bN-LKYO!97SN@;+U!2Z_|1BgR4Ox#@{*V2yPv@EcBd=PlQ{a{V z1OF+~IrYDV3@XG%q|5?%*`#CFz5QoT=g)5=uUf40<7L(VB_Ut_bP^!M z9l?+HZ9>+sxLkg8=1(V@Kxlt{ygw(rrT_ftgvuG+oFDJ|g!l9R{qDd1c7<&v+RxDb zY%rh9b2I;+&>;9kgvuG+oFDIg!aMoDzdM2LyOE;(4DG+WOOKbg@t;4AP&uQU^W#09 zkkx<9B?2NK0wN#+A|L`HAOa#F0wN#+A|L`HAOa#F0wN#+A|L`HAOa#F0wN#+A|L`H zAOa#F0wN#+A|L`HAOa#F0wN#+A|L`HAOa#F0wN#+A|L`HAOa#F0wN#+A|L`HAOa#F M0wN#+B9Kqu|Lsp_j{pDw literal 196730 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 Tfd412@9dTTw;X>FIFrCH8FsMw From 9dd86a266bd3b6bf6bc2ce9e4b60c2b47255b143 Mon Sep 17 00:00:00 2001 From: eri451 Date: Sat, 25 Jan 2014 18:27:39 +0100 Subject: [PATCH 8/8] alles neu Die Objkte sind jetzt in einzelnen Dateien. Die Tastatur regelt die Rotation der Szene. lesson2.c wurde in animation.c umbenannt und entsprechend bearbeitet. --- lesson02/{lesson2.c => animation.c} | 121 ++++++---------------------- lesson02/closeBracket.c | 87 ++++++++++++++++++++ lesson02/closeBracket.h | 6 ++ lesson02/makefile | 42 ++-------- lesson02/openBracket.c | 4 +- lesson02/openBracket.h | 6 +- lesson02/slash.c | 4 +- lesson02/slash.h | 2 +- 8 files changed, 133 insertions(+), 139 deletions(-) rename lesson02/{lesson2.c => animation.c} (64%) create mode 100644 lesson02/closeBracket.c create mode 100644 lesson02/closeBracket.h diff --git a/lesson02/lesson2.c b/lesson02/animation.c similarity index 64% rename from lesson02/lesson2.c rename to lesson02/animation.c index d88a005..eddf45b 100755 --- a/lesson02/lesson2.c +++ b/lesson02/animation.c @@ -17,6 +17,7 @@ #include "slash.h" #include "openBracket.h" +#include "closeBracket.h" #define PI 3.1415 @@ -30,6 +31,10 @@ float xrot = 0.0f; float yrot = 0.0f; float zrot = 0.0f; +float xrot_scene = 0.0f; +float yrot_scene = 0.0f; +float zrot_scene = 0.0f; + float i = 0.3; int full = 0; int oszi = 0; @@ -192,7 +197,7 @@ void ReSizeGLScene(int Width, int Height) glMatrixMode(GL_MODELVIEW); } -void rota(int what) +void rotate(int what) { usleep(10); switch(what) @@ -216,77 +221,6 @@ void rota(int what) if (zrot >= 360) zrot = 0; } - -void DrawCloseBracket(){ - // draw a square (quadrilateral) - glBegin(GL_QUADS); // start drawing a polygon (4 sided) - - // Down - // Front Face (note that the texture's corners have to match the quad's corners) - glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad - - // Back Face - glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Bottom Left Of The Texture and Quad - - // Bottom Face - glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, -0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.4f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad - - // Right face - glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.4f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad - - // Left Face - glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad - - // Up - // Front Face (note that the texture's corners have to match the quad's corners) - glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.4f, 0.5f, 0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Top Left Of The Texture and Quad - - // Back Face - glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Bottom Left Of The Texture and Quad - - // Top Face - glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.4f, 0.5f, 0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad - - // Left Face - glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.2f, -0.0f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.2f, -0.0f, 0.5f); // Bottom Left Of The Texture and Quad - - // Right face - glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.4f, 0.5f, 0.5f); // Top Left Of The Texture and Quad - - glEnd(); // done with the polygon -} - - /* The main drawing function. */ void DrawGLScene() { @@ -296,40 +230,35 @@ void DrawGLScene() glTranslatef(0.0f,0.0f,-8.0f); // Move Left 1.5 Units And Into The Screen 6.0 - glRotatef(xrot, 1.0f, 0.0f, 0.0f); - glRotatef(yrot, 0.0f, 0.0f, 0.0f); - glRotatef(zrot, 0.0f, 0.0f, 1.0f); + glRotatef(xrot_scene, 1.0f, 0.0f, 0.0f); + glRotatef(yrot_scene, 0.0f, 1.0f, 0.0f); + glRotatef(zrot_scene, 0.0f, 0.0f, 1.0f); glTranslatef(0.0f, sin((yrot*PI)/180), 0.0f); glBindTexture(GL_TEXTURE_2D, texture[0]); // choose the texture to use. glTranslatef(-3.0f, 0.0f, 0.0f); - DrawOpenBracket( 0.0f, yrot, 0.0f); + DrawOpenBracket( xrot, yrot, zrot, texture[0]); glTranslatef(1.2f, 0.0f, 0.0f); - DrawOpenBracket( 0.0f, yrot, 0.0f); + DrawOpenBracket( xrot, yrot, zrot, texture[0]); glTranslatef(1.2f, 0.0f, 0.0f); - DrawOpenBracket( 0.0f, yrot, 0.0f); + DrawOpenBracket( xrot, yrot, zrot, texture[0]); glTranslatef(1.2f, 0.0f, 0.0f); - DrawSlash(0.0f, yrot, 0.0f); + DrawSlash(xrot, yrot, zrot, texture[0]); glTranslatef(1.2f, 0.0f, 0.0f); - glRotatef(yrot, 0.0f, 1.0f, 0.0f); - DrawCloseBracket(); - glRotatef(yrot, 0.0f,-1.0f, 0.0f); + DrawCloseBracket(xrot, yrot, zrot, texture[0]); glTranslatef(1.2f, 0.0f, 0.0f); - glRotatef(yrot, 0.0f, 1.0f, 0.0f); - DrawCloseBracket(); - glRotatef(yrot, 0.0f,-1.0f, 0.0f); - + DrawCloseBracket(xrot, yrot, zrot, texture[0]); // swap buffers to display, since we're double buffered. glutSwapBuffers(); - if (oszi) rota(1); + if (oszi) rotate(1); } /* The function called whenever a key is pressed. */ @@ -359,10 +288,12 @@ void keyPressed(unsigned char key, int x, int y) break; case ' ': - zrot += 5; + zrot_scene += 5; + break; + + case '0': zrot_scene = xrot_scene = yrot_scene = 0; break; - case '0': zrot = xrot = yrot = 0; break; case 27: glutDestroyWindow(window); exit(0); default: @@ -378,20 +309,16 @@ void specialKeyPressed(int key, int x, int y) switch (key) { case GLUT_KEY_UP: - xrot += 5; - oszi = 0; + xrot_scene += 5; break; case GLUT_KEY_DOWN: - xrot -= 5; - oszi = 0; + xrot_scene -= 5; break; case GLUT_KEY_LEFT: - yrot += 5; - oszi = 0; + yrot_scene += 5; break; case GLUT_KEY_RIGHT: - yrot -= 5; - oszi = 0; + yrot_scene -= 5; break; default: break; diff --git a/lesson02/closeBracket.c b/lesson02/closeBracket.c new file mode 100644 index 0000000..eecbf9e --- /dev/null +++ b/lesson02/closeBracket.c @@ -0,0 +1,87 @@ +#include // Header File For The GLUT Library +#include // Header File For The OpenGL32 Library +#include // Header File For The GLu32 Library + +void DrawCloseBracket(float xrot, float yrot, float zrot, GLuint texture) +{ + glRotatef(xrot, 1.0f, 0.0f, 0.0f); + glRotatef(yrot, 0.0f, 1.0f, 0.0f); + glRotatef(zrot, 0.0f, 0.0f, 1.0f); + + glBindTexture(GL_TEXTURE_2D, texture); + + // draw a square (quadrilateral) + glBegin(GL_QUADS); // start drawing a polygon (4 sided) + + // Down + // Front Face (note that the texture's corners have to match the quad's corners) + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad + + // Back Face + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Bottom Left Of The Texture and Quad + + // Bottom Face + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.4f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad + + // Right face + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.4f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + + // Left Face + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad + + // Up + // Front Face (note that the texture's corners have to match the quad's corners) + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.4f, 0.5f, 0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Top Left Of The Texture and Quad + + // Back Face + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Bottom Left Of The Texture and Quad + + // Top Face + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.4f, 0.5f, 0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad + + // Left Face + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.2f, -0.0f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.2f, -0.0f, 0.5f); // Bottom Left Of The Texture and Quad + + // Right face + glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.4f, 0.5f, 0.5f); // Top Left Of The Texture and Quad + + glEnd(); // done with the polygon + + glRotatef(xrot,-1.0f, 0.0f, 0.0f); + glRotatef(yrot, 0.0f,-1.0f, 0.0f); + glRotatef(zrot, 0.0f, 0.0f,-1.0f); + +} + +/* vim: set et sw=4 ts=4: */ + diff --git a/lesson02/closeBracket.h b/lesson02/closeBracket.h new file mode 100644 index 0000000..7e1b621 --- /dev/null +++ b/lesson02/closeBracket.h @@ -0,0 +1,6 @@ +#ifndef CLOSEBRACKET_H +#define CLOSEBRACKET_H + +void DrawCloseBracket(float xrot, float yrot, float zrot, GLuint texture); + +#endif diff --git a/lesson02/makefile b/lesson02/makefile index 41b2245..583143c 100755 --- a/lesson02/makefile +++ b/lesson02/makefile @@ -5,47 +5,17 @@ COMPILERFLAGS = -Wall CC = gcc CFLAGS = $(COMPILERFLAGS) $(INCLUDE) LIBRARIES = -lX11 -lXi -lXmu -lglut -lGL -lGLU -lm -OBJECTS = $(patsubst %.c, %.o, $(wildcard ./*.c)) +OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c)) -# for all, set the targets to be every lesson1.c-lesson13.c -# file, removing the .c extension. That is, at this point, -# it would produce lesson1, lesson2, lesson3,...,lesson13 targets. -# -all: $(basename $(wildcard lesson[1-9].c lesson1[0-3].c)) - -# same as for all, except set the targets to be -# lessonX.tar.gz from lessonX.c. This is really -# only used to build smaller tutorial .tar.gz files -# to send to nehe. -# -dist: $(foreach file,$(basename $(wildcard lesson[1-9].c lesson1[0-3].c)),$(file).tar.gz) - -# to produce, say, lesson1.tar.gz: -# -# 1. remove lesson1.tar.gz -# 2. build lesson1.tar containing README, makefile, lesson1.c, Data/lesson1/*. -# 3. gzip lesson1.tar. -# -lesson%.tar.gz : - tar cvf $(subst .tar.gz,.tar,$@) README makefile $(subst .tar.gz,.c,$@) $(wildcard Data/$(subst .tar.gz,,$@)/*); \ - gzip $(subst .tar.gz,.tar,$@); - -# to produce, say, lesson1: -# -# 1. compile the thing. uses the variables defined above. -# -lesson% : lesson%.o $(OBJECTS) - $(CC) $(CFLAGS) -o $@ $(OBJECTS) $(LIBDIR) $(LIBRARIES) +all : $(OBJECTS) + $(CC) $(CFLAGS) -o animation $(OBJECTS) $(LIBDIR) $(LIBRARIES) # to clean up: -# delete all of the lessonX files. clean: - rm $(wildcard lesson[1-9] lesson1[0-3]) + rm -f ./animation; + rm -f *.o -# to clean up the distributions: -# delete all of the lessonX.tar.gz files. -distclean: - rm $(wildcard lesson[1-9].tar.gz lesson1[0-3].tar.gz) +# to compile all .c %.o: %.c $(CC) -c -o $@ $< diff --git a/lesson02/openBracket.c b/lesson02/openBracket.c index 4845bc2..7701c22 100644 --- a/lesson02/openBracket.c +++ b/lesson02/openBracket.c @@ -3,12 +3,14 @@ #include // Header File For The GLu32 Library -void DrawOpenBracket(float xrot, float yrot, float zrot) +void DrawOpenBracket(float xrot, float yrot, float zrot, GLuint texture) { glRotatef(xrot, 1.0f, 0.0f, 0.0f); glRotatef(yrot, 0.0f, 1.0f, 0.0f); glRotatef(zrot, 0.0f, 0.0f, 1.0f); + glBindTexture(GL_TEXTURE_2D, texture); + // draw a square (quadrilateral) glBegin(GL_QUADS); // start drawing a polygon (4 sided) diff --git a/lesson02/openBracket.h b/lesson02/openBracket.h index 0ddccf9..8a0fd7a 100644 --- a/lesson02/openBracket.h +++ b/lesson02/openBracket.h @@ -1,11 +1,11 @@ -#ifndef SLASH_H -#define SLASH_H +#ifndef OPENBRACKET_H +#define OPENBRACKET_H /* * Draw a textured 2 boxed sharp opening bracket * rotate the object with the 3 args */ -void DrawOpenBracket(float xrot, float yrot, float zrot); +void DrawOpenBracket(float xrot, float yrot, float zrot, GLuint texture); #endif diff --git a/lesson02/slash.c b/lesson02/slash.c index 7260c2f..2771252 100644 --- a/lesson02/slash.c +++ b/lesson02/slash.c @@ -3,12 +3,14 @@ #include // Header File For The GLu32 Library -void DrawSlash(float xrot, float yrot, float zrot){ +void DrawSlash(float xrot, float yrot, float zrot, GLuint texture){ glRotatef(xrot, 1.0f, 0.0f, 0.0f); glRotatef(yrot, 0.0f, 1.0f, 0.0f); glRotatef(zrot, 0.0f, 0.0f, 1.0f); + glBindTexture(GL_TEXTURE_2D, texture); // choose the texture to use. + // draw a square (quadrilateral) glBegin(GL_QUADS); // start drawing a polygon (4 sided) diff --git a/lesson02/slash.h b/lesson02/slash.h index 61f10e1..f57ed96 100644 --- a/lesson02/slash.h +++ b/lesson02/slash.h @@ -6,6 +6,6 @@ * rotate the object with the 3 args */ -void DrawSlash(float xrot, float yrot, float zrot); +void DrawSlash(float xrot, float yrot, float zrot, GLuint texture); #endif