Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "GLAux.h"
- #include "glut.h"
- #include "stdio.h"
- #pragma comment(lib, "opengl32.lib")
- #pragma comment(lib, "glut32.lib")
- #pragma comment(lib, "glaux.lib")
- float re,we,qe,te,fe,ge;
- float map [40][40];
- int x,y;
- int x0,y0;
- float max=0,min=0;
- unsigned int grass, road, wood;
- void RenderScene() {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glViewport(0, 0, 600, 600);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(45.0f, 1.0f, 0.1f, 100.0f);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0, 0, te - 70);
- glRotatef(re, 0, 0, 1);
- glRotatef(we, 1, 0, 0);
- glRotatef(qe, 0, 1, 0);
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, grass);
- glBegin(GL_QUADS);
- glTexCoord2f(1, 1);
- glVertex3f(20,20,0);
- glTexCoord2f(1,0);
- glVertex3f(20,-20,0);
- glTexCoord2f(0,0);
- glVertex3f(-20,-20,0);
- glTexCoord2f(0,1);
- glVertex3f(-20,20,0);
- glEnd();
- glBindTexture(GL_TEXTURE_2D, road);
- glBegin(GL_QUADS);
- glTexCoord2f(1, 1);
- glVertex3f(10, 20, 0.01);
- glTexCoord2f(0, 1);
- glVertex3f(0, 20, 0.01);
- glTexCoord2f(0, 0);
- glVertex3f(0, -20, 0.01);
- glTexCoord2f(1, 0);
- glVertex3f(10, -20, 0.01);
- glEnd();
- glBindTexture(GL_TEXTURE_2D, wood);
- glBegin(GL_QUADS);
- glTexCoord2f(1, 1);
- glVertex3f(-8, 12, 0.01);
- glTexCoord2f(0, 1);
- glVertex3f(-12, 12, 0.01);
- glTexCoord2f(0, 0);
- glVertex3f(-12, 8, 0.01);
- glTexCoord2f(1, 0);
- glVertex3f(-8, 8, 0.01);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(1, 1);
- glVertex3f(-8, 12, 0.01);
- glTexCoord2f(0, 1);
- glVertex3f(-8, 12, 3.01);
- glTexCoord2f(0, 0);
- glVertex3f(-12, 12, 3.01);
- glTexCoord2f(1, 0);
- glVertex3f(-12, 12, 0.01);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(1, 1);
- glVertex3f(-12, 12, 0.01);
- glTexCoord2f(0, 1);
- glVertex3f(-12, 12, 3.01);
- glTexCoord2f(0, 0);
- glVertex3f(-12, 8, 3.01);
- glTexCoord2f(1, 0);
- glVertex3f(-12, 8, 0.01);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(1, 1);
- glVertex3f(-12, 8, 0.01);
- glTexCoord2f(0, 1);
- glVertex3f(-12, 8, 3.01);
- glTexCoord2f(0, 0);
- glVertex3f(-8, 8, 3.01);
- glTexCoord2f(1, 0);
- glVertex3f(-8, 8, 0.01);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(1, 1);
- glVertex3f(-8, 8, 0.01);
- glTexCoord2f(0, 1);
- glVertex3f(-8, 8, 3.01);
- glTexCoord2f(0, 0);
- glVertex3f(-8, 12, 3.01);
- glTexCoord2f(1, 0);
- glVertex3f(-8, 12, 0.01);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(1, 1);
- glVertex3f(-8, 12, 3.01);
- glTexCoord2f(0, 1);
- glVertex3f(-12, 12, 3.01);
- glTexCoord2f(0, 0);
- glVertex3f(-12, 8, 3.01);
- glTexCoord2f(1, 0);
- glVertex3f(-8, 8, 3.01);
- glEnd();
- glDisable(GL_TEXTURE_2D);
- glColor3f(0, 1, 0);
- //первая елка
- glPushMatrix();
- glTranslatef(-10, -15, 3);
- glutSolidCone(5, 10, 10, 10);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-10, -15, 9);
- glutSolidCone(5, 6, 6, 6);
- glPopMatrix();
- //вторая
- glPushMatrix();
- glTranslatef(-10, 10, 3);
- glutSolidCone(5, 10, 10, 10);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-10, 10, 9);
- glutSolidCone(5, 6, 6, 6);
- glPopMatrix();
- glPushMatrix();
- glColor3f(0.51, 0.25, 0);
- glTranslatef(-10, -15, 1.51);
- glutSolidCube(3);
- glPopMatrix();
- //снег
- glPushMatrix();
- glColor3f(1, 1, 1);
- glTranslatef(15, -5, 3);
- glutSolidSphere(3, 5, 5);
- glPopMatrix();
- glPushMatrix();
- glColor3f(1, 1, 1);
- glTranslatef(15, -5, 6.5);
- glutSolidSphere(2, 5, 5);
- glPopMatrix();
- glPushMatrix();
- glColor3f(1, 1, 1);
- glTranslatef(15, -5, 9);
- glutSolidSphere(1, 5, 5);
- glPopMatrix();
- glPushMatrix();
- glColor3f(1, 1, 1);
- glTranslatef(15, -5, 1);
- glutSolidCube(1);
- glPopMatrix();
- glutSwapBuffers();
- }
- void ReadKeyBoard(unsigned char key, int, int) //считываем клавишу
- {
- if (key=='q') //нажав q поворот на 15 градусов вокруг z
- re+=15;
- if (key=='e')//вокруг x
- we-=15;
- if (key=='w')//вокруг y
- qe-=15;
- if (key==27) exit(0);
- if (key=='='){
- if ((te+1)<0)
- te+=1;
- }
- if (key=='-')
- te-=1;
- glutPostRedisplay();
- }
- /*void Idle()
- {
- ge-=0.1;
- }*/
- void Mouse1(int button, int state, int x, int y)
- {
- if (state==GLUT_DOWN)
- {
- x0=x;
- y0=y;
- }
- }
- void Mouse2(int x, int y)
- {
- we=y-y0;
- qe=x-x0;
- glutPostRedisplay();
- }
- int main(int argc, char *argv[]) {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- glutInitWindowPosition(100, 100);
- glutInitWindowSize(600, 600);
- glutCreateWindow("Пример вывода 3D графики");
- glEnable(GL_DEPTH_TEST);
- glClearColor(0, 0, 0, 1);
- AUX_RGBImageRec *p_texture = auxDIBImageLoad("grass_02.bmp");
- glGenTextures(1, &grass);
- glBindTexture(GL_TEXTURE_2D, grass);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexImage2D(GL_TEXTURE_2D, 0, 3, p_texture->sizeX, p_texture->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, p_texture->data);
- p_texture = auxDIBImageLoad("roof_03.bmp");
- glGenTextures(1, &road);
- glBindTexture(GL_TEXTURE_2D, road);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexImage2D(GL_TEXTURE_2D, 0, 3, p_texture->sizeX, p_texture->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, p_texture->data);
- p_texture = auxDIBImageLoad("roof_03.bmp");
- glGenTextures(1, &wood);
- glBindTexture(GL_TEXTURE_2D, wood);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexImage2D(GL_TEXTURE_2D, 0, 3, p_texture->sizeX, p_texture->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, p_texture->data);
- glEnable(GL_TEXTURE_2D);
- glutDisplayFunc(RenderScene);
- //glEnable(GL_LIGHTING);
- //glEnable(GL_LIGHT0);
- // glutIdleFunc(Idle);
- glutKeyboardFunc(ReadKeyBoard);
- glutMouseFunc(Mouse1);
- glutMotionFunc(Mouse2);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement