#include<stdlib.h>
#include<GL/glut.h>
#include<GL/glu.h>
#include<GL/gl.h>
/* g++ class.cpp -o cla -lGL -lGLU -lglut -lSDL */
int refreshMillis = 30;
GLubyte rasters[24] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,0xff,
0xff, 0xff, 0xff };
GLubyte rasterz[100] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00};
class kloc
{
public:
void klocek1()
{
glPushMatrix();
glRasterPos2i (50, 100);
glBitmap (10, 10, 0.0, 0.0, 10.0, 0.0, rasters);
glPopMatrix();
}
void klocek2()
{
glPushMatrix();
glRasterPos2i (50, 50);
glBitmap (10, 10, 0.0, 0.0, 0.0, 10.0, rasters);
glBitmap (10, 10, 0.0, 0.0, 10.0, 0.0, rasters);
glPopMatrix();
}
int klocek3()
{
glPushMatrix();
glRasterPos2i (50, 50);
glBitmap (10, 10, 0.0, 0.0, 10.0, 0.0, rasters);
glBitmap (10, 10, 0.0, 0.0, 0.0, 10.0, rasters);
glBitmap (10, 10, 0.0, 0.0, 10.0, 10.0, rasters);
glPopMatrix();
}
};
class stoc
{
public:
void stos()
{
glPushMatrix();
glBitmap (10, 10, 0.0, 0.0, 100, 100, rasterz);
glPopMatrix();
}
};
void update()
{
stoc *stoz= new stoc;
kloc *klocek= new kloc;
glTranslatef(0.0, -0.2, 0.0);
klocek->klocek1();
stoz->stos();
}
void init(void)
{
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
glClearColor (0.0, 0.0, 0.0, 0.0);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
update();
glFlush();
glutSwapBuffers ();
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho (0, w, 0, h, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
}
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
}
}
void Timer(int value) //kopjuj wklej p.
{
glutPostRedisplay(); // Post a paint request to activate display()
glutTimerFunc(refreshMillis, Timer, 0); // subsequent timer call at milliseconds
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(100, 100);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutTimerFunc(0, Timer, 0);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
No comments:
Post a Comment