TEXTURAS2D

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

#include <GL/glut.

h>

#include <stdlib.h>

#include <stdio.h>

#include<math.h>

#define GL_PI 3.1415f

#define glRGB(x, y,z) glColor3ub((GLubyte)y, (GLbyte)z)

unsigned char Colores[4][4][3]={

{{64,0,0},{128,0,0}, {192,0,0}, {255,0,0}}, //Rojos

{{0,64,0},{0,128,0},{0,192,0},{0,255,0}}, //Verdes

{{0,0,64},{0,0,128},{0,0,192},{0,0,255}}, //Azules

{{64,64,0},{128,128,0},{192,192,0},{255,255,0}} //Amarillos

};

void reshape (int width, int height){

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

//

glMatrixMode(GL_MODELVIEW);

glViewport(0,0, width,height);

glLoadIdentity();

glMatrixMode(GL_MODELVIEW);

void PintaArcoIris(){

glClearColor(0,0,0,0);

//

glEnable(GL_TEXTURE_2D);

//

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,4,4,0,GL_RGB, GL_UNSIGNED_BYTE,Colores);
//

//

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

//

/*

//pa un solo cuadrado con texturas

glBegin(GL_QUADS);

glTexCoord2f(0.0, 1.0); glVertex3f(-0.5, -0.5, 0);

glTexCoord2f(1.0, 1.0); glVertex3f(0.5, -0.5, 0);

glTexCoord2f(1.0, 0.0); glVertex3f(0.5, 0.5, 0);

glTexCoord2f(0.0, 0.0); glVertex3f(-0.5, 0.5, 0);

glEnd();

*/

glBegin(GL_QUADS);

glTexCoord2f(-1.0, 2.0); glVertex3f(-0.5, -0.5, 0);

glTexCoord2f(2.0, 2.0); glVertex3f(0.5, -0.5, 0);

glTexCoord2f(2.0, -1.0); glVertex3f(0.5, 0.5, 0);

glTexCoord2f(-1.0, -1.0); glVertex3f(-0.5, 0.5, 0);

glEnd();

glutSwapBuffers();

glFlush();

/*

glBegin(GL_TRIANGLES);

glTexCoord2d(0.0,1.0);

glVertex3f(-0.5,-0.5, 0.5);

glTexCoord2d(1.0,1.0);

glVertex3f(0.5,-0.5,0.5);

glTexCoord2d(0.5,0.0);

glVertex3f(0.0,0.5,0.5);
glEnd();

glutSwapBuffers();

glFlush();

*/

int main(int argc, char **argv){

glutInit(&argc,argv);

glutInitWindowPosition(100,100);

glutInitWindowSize(400,400);

glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);

glutCreateWindow("Textura 2D");

glutDisplayFunc(PintaArcoIris);

glutReshapeFunc(reshape);

glutMainLoop();

return 0;

You might also like