1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
#include <SDL/SDL.h>
#include <GL/glew.h>
static unsigned char texture[3 * 800 * 600];
GLuint textureID = 0;
static float alpha = 20;
int main(int argc, char **argv) {
// Variables
bool stopBool = false;
SDL_Event event;
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTTHREAD);
SDL_SetVideoMode(800, 600, 16, SDL_ANYFORMAT | SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_OPENGL);
// glewInit();
//glShadeModel(GL_SMOOTH);
//glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST); // Z-buffer
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 800, 600, 0, GL_RGB, GL_UNSIGNED_BYTE, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glBindTexture(GL_TEXTURE_2D, 0);
while (!stopBool) { // loop
glClearColor(1, 1, 1, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Cube drawing
glPushMatrix();
glRotatef(alpha, 0.3, 0.3, 0);
glBegin(GL_QUADS);
glColor3d(1, 0, 0);
glVertex3f(0.3, 0.3, -0.4);
glVertex3f(0.7, 0.3, -0.4);
glVertex3f(0.7, 0.7, -0.4);
glVertex3f(0.3, 0.7, -0.4);
glColor3d(0, 1, 0);
glVertex3f(0.3, 0.3, 0.0);
glVertex3f(0.3, 0.3, -0.4);
glVertex3f(0.3, 0.7, -0.4);
glVertex3f(0.3, 0.7, 0.0);
glColor3d(0, 1, 1);
glVertex3f(0.7, 0.3, 0.0);
glVertex3f(0.7, 0.3, -0.4);
glVertex3f(0.7, 0.7, -0.4);
glVertex3f(0.7, 0.7, 0.0);
glColor3d(1, 1, 0);
glVertex3f(0.3, 0.7, 0.0);
glVertex3f(0.7, 0.7, 0.0);
glVertex3f(0.7, 0.7, -0.4);
glVertex3f(0.3, 0.7, -0.4);
glColor3d(1, 0, 1);
glVertex3f(0.3, 0.3, 0.0);
glVertex3f(0.7, 0.3, 0.0);
glVertex3f(0.7, 0.3, -0.4);
glVertex3f(0.3, 0.3, -0.4);
glColor3d(0, 0, 1);
glVertex3f(0.3, 0.3, 0.0);
glVertex3f(0.7, 0.3, 0.0);
glVertex3f(0.7, 0.7, 0.0);
glVertex3f(0.3, 0.7, 0.0);
glEnd();
glPopMatrix();
// End cube drawing
glFlush();
glBindTexture(GL_TEXTURE_2D, textureID);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 800, 600);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Square drawing
glColor3d(1, 1, 1);
glBegin(GL_QUADS);
glTexCoord2d(0, 0);
glVertex2d(-0.9, -1);
glTexCoord2d(0, 1);
glVertex2d(-1, 1);
glTexCoord2d(1, 1);
glVertex2d(1, 1);
glTexCoord2d(1, 0);
glVertex2d(1, -1);
glEnd();
// End square drawing
glBindTexture(GL_TEXTURE_2D, 0);
SDL_GL_SwapBuffers();
SDL_Delay(1);
alpha = alpha + 0.1;
// Events
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_KEYDOWN:
switch (event.key.keysym.sym) {
case SDLK_ESCAPE:
stopBool = true;
break;
default:
break;
}
}
}
}
SDL_Quit();
return 0;
}
// #EOF |