Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <GL/glut.h>
- #include<windows.h>
- #include <cmath>
- using namespace std;
- void iniciarPantalla(){
- glClearColor(0.392157,1 /*0.584314*/,0.929412,0.0);//(rojo,verde,azul)
- glMatrixMode(GL_PROJECTION);
- gluOrtho2D(0.0,200.0,0.0,150.0);//proyeccion ortogonal en 2 dimensiones
- }
- void rectangulos(int x0,int y0,int x1,int y1,int x2, int y2,int x3, int y3, float R,float G,float B)
- {
- glColor3f(R,G,B);
- glBegin(GL_QUADS);
- glVertex2f(x0, y0);
- glVertex2f(x1,y1);
- glVertex2f(x2,y2);
- glVertex2f(x3,y3);
- glEnd();
- }
- void piso()
- {
- rectangulos(0,40,0,0,200,0,200,40,0.07421875,0.94140625,0.35546875); //superficie verde
- }
- void triangulos(int x0,int y0,int x1,int y1,int x2, int y2,float R,float G,float B)
- {
- glColor3f(R,G,B);
- glBegin(GL_TRIANGLES);
- glVertex2f(x0, y0);
- glVertex2f(x1,y1);
- glVertex2f(x2,y2);
- glEnd();
- }
- void arbol()
- {
- float R, G, B;
- R=0.870588;
- G=0.721569;
- B=0.529412;
- rectangulos(114,60,114,40,116,40,116,60,R,G,B); //tallo
- glBegin(GL_POLYGON); //octagono
- glColor3f(0,1,0);
- glVertex2f(115, 68);
- glVertex2f(112,67);
- glVertex2f(111,64);
- glVertex2f(112, 61);
- glVertex2f(115,60);
- glVertex2f(118,61);
- glVertex2f(119, 64);
- glVertex2f(118,67);
- glEnd();
- }
- void sol()
- {
- glBegin(GL_POLYGON);
- for(int i=0;i<360;i=i+45)
- {
- glColor3f(1,0.843137, 0);
- float degInRad=i*3.14159265/180;
- glVertex2f((cos(degInRad)*12)+180,(sin(degInRad)*12)+130);
- }
- glEnd();
- glBegin(GL_POLYGON);
- for(int i=0;i<360;i++)
- {
- glColor3f(1,1,0);
- float degInRad=i*3.14159265/180;
- glVertex2f((cos(degInRad)*10)+180,(sin(degInRad)*10)+130);
- }
- glEnd();
- }
- void nubes(){
- glBegin(GL_POLYGON);
- int j=30;
- while(j<=40){
- for(int i=0;i<360;i++)
- {
- glColor3f(0.941176,0.972549,1);
- float degInRad=i*3.14159265/180;
- glVertex2f((cos(degInRad)*5)+j,(sin(degInRad)*5)+130);
- }
- j=j+5;
- }
- j=30;
- while(j<=40){
- for(int i=0;i<360;i++)
- {
- glColor3f(0.941176,0.972549,1);
- float degInRad=i*3.14159265/180;
- glVertex2f((cos(degInRad)*5)+j,(sin(degInRad)*5)+125);
- }
- j=j+5;
- }
- glEnd();
- glBegin(GL_POLYGON);
- j=60;
- while(j<=70){
- for(int i=0;i<360;i++)
- {
- glColor3f(0.941176,0.972549,1);
- float degInRad=i*3.14159265/180;
- glVertex2f((cos(degInRad)*5)+j,(sin(degInRad)*5)+130);
- }
- j=j+5;
- }
- j=60;
- while(j<=70){
- for(int i=0;i<360;i++)
- {
- glColor3f(0.941176,0.972549,1);
- float degInRad=i*3.14159265/180;
- glVertex2f((cos(degInRad)*5)+j,(sin(degInRad)*5)+125);
- }
- j=j+5;
- }
- glEnd();
- glBegin(GL_POLYGON);
- j=90;
- while(j<=100){
- for(int i=0;i<360;i++)
- {
- glColor3f(0.941176,0.972549,1);
- float degInRad=i*3.14159265/180;
- glVertex2f((cos(degInRad)*5)+j,(sin(degInRad)*5)+130);
- }
- j=j+5;
- }
- j=90;
- while(j<=100){
- for(int i=0;i<360;i++)
- {
- glColor3f(0.941176,0.972549,1);
- float degInRad=i*3.14159265/180;
- glVertex2f((cos(degInRad)*5)+j,(sin(degInRad)*5)+125);
- }
- j=j+5;
- }
- glEnd();
- j=120;
- while(j<=130){
- for(int i=0;i<360;i++)
- {
- glColor3f(0.941176,0.972549,1);
- float degInRad=i*3.14159265/180;
- glVertex2f((cos(degInRad)*5)+j,(sin(degInRad)*5)+130);
- }
- j=j+5;
- }
- j=120;
- while(j<=130){
- for(int i=0;i<360;i++)
- {
- glColor3f(0.941176,0.972549,1);
- float degInRad=i*3.14159265/180;
- glVertex2f((cos(degInRad)*5)+j,(sin(degInRad)*5)+125);
- }
- j=j+5;
- }
- glEnd();
- }
- void cerros()
- {
- float R, G, B;
- R=0.870588;
- G=0.721569;
- B=0.529412;
- triangulos(30,0,50,80,70,0,R,G,B); //segundo cerro
- triangulos(60,0,80,80,100,0,R,G,B); //tercer cerro
- triangulos(0,0,20,80,40,0,R,G,B); //primercerro
- triangulos(15,60,20,80,25,60,1,1,1); //primer
- triangulos(45,60,50,80,55,60,1,1,1); //segund
- triangulos(75,60,80,80,85,60,1,1,1); //tercero
- }
- void dibujarlinea(int x0,int y0,int xfin,int yfin,float R,float G,float B){
- glColor3f(R,G,B);
- glBegin(GL_LINES);
- glVertex2i(x0,y0);
- glVertex2i(xfin,yfin);
- glEnd();
- }
- void Casita(){
- rectangulos(140,60,140,40,160,40,160,60,1.0,0.980392,0.803922);
- triangulos(140,60,150,70,160,60,1,1,1);
- triangulos(160,60,150,70,160,70,0.862745,0.0784314,0.235294);
- rectangulos(160,60,160,40,190,40,190,60,1.0,0.980392,0.803922);
- rectangulos(160,70,160,60,180,60,180,70,0.862745,0.0784314,0.235294);
- triangulos(180,60,180,70,190,60,0.862745,0.0784314,0.235294);
- rectangulos(145,50,145,40,155,40,155,50,0.545098,0.270588,0.0745098);
- rectangulos(165,55,165,45,185,45,185,55,0.545098,0.270588,0.0745098);
- }
- void camino(){
- rectangulos(145,38,110,0,120,0,155,38,1,0.843137,0);
- }
- void Plantitas(){
- float R,G,B;
- R=0.0;
- G=0.2941176470588235;
- B=0.0;
- int i=0,a=10;
- int b=10;
- int cont=0;
- while(cont<3){
- while(a<200)
- {
- dibujarlinea(a,i-2.5,a,i+2.5,R,G,B);
- dibujarlinea(a,i-1.5,a-2.5,i+1,R,G,B);
- dibujarlinea(a,i-1.5,a+3,i+1,R,G,B);
- dibujarlinea(a,i,a-2.5,i+3,R,G,B);
- dibujarlinea(a,i,a+3,i+3,R,G,B);
- a=a+6;
- }
- a=b;
- i=i+5;
- cont++;
- }
- }
- void FondoDeEscritorio(){
- glClear(GL_COLOR_BUFFER_BIT);//ya pone el color de fondo en la pantalla
- glColor3f(1.0,0.0,0.0);//(rojo,verde,azul)
- piso();
- cerros();
- camino();
- Plantitas();
- Casita();
- arbol();
- sol();
- nubes();
- glFlush();
- }
- int main(int argc, char *argv[])
- {
- glutInit(&argc,argv);
- glutInitWindowPosition(0,0);
- glutInitWindowSize(600,500);
- glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
- glutCreateWindow("Nuestro Primer Programa");
- iniciarPantalla();
- glutDisplayFunc(FondoDeEscritorio);
- glutMainLoop();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement