CUBE MAP
Una textura cubemap es una textura , donde cada nivel en mapas MIP consiste en seis imágenes en 2D. Las imágenes están dispuestas en una forma de cubo, de ahí el nombre. Cubemaps pueden tener múltiples niveles de mipmap.
CAPTURAS
Imagenes usadas:
Back |
Bottom |
Left |
Rigth |
Front |
Top |
CODIGO
#include<stdio.h>
#include<stdlib.h>
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <windows.h>
#include <math.h>
#define PI 3.14159
using namespace std;
int HL=1,angx=30,angy=60;
unsigned char * datos;
float a;
int an1=512,al1=512;//dim imagenes, ancho, alto
unsigned char * imagen1;
unsigned char * imagen2;
unsigned char * imagen3;
unsigned char * imagen4;
unsigned char * imagen5;
unsigned char * imagen6;
int leerImagen1(){
FILE *imagen;
imagen=fopen("C:/ImagenesC/cubo/bottom.raw","r");
imagen1=(unsigned char*)malloc(an1*al1*3);
if(imagen==NULL){
printf("Error: No imagen");
return 0;
}
fread(imagen1,an1*al1*3,1,imagen);
fclose(imagen);
return 1;
}
int leerImagen2(){
FILE *imagen;
imagen=fopen("C:/ImagenesC/cubo/back.raw","r");
imagen2=(unsigned char*)malloc(an1*al1*3);
if(imagen==NULL){
printf("Error: No imagen");
return 0;
}
fread(imagen2,an1*al1*3,1,imagen);
fclose(imagen);
return 1;
}
int leerImagen3(){
FILE *imagen;
imagen=fopen("C:/ImagenesC/cubo/left.raw","r");
imagen3=(unsigned char*)malloc(an1*al1*3);
if(imagen==NULL){
printf("Error: No imagen");
return 0;
}
fread(imagen3,an1*al1*3,1,imagen);
fclose(imagen);
return 1;
}
int leerImagen4(){
FILE *imagen;
imagen=fopen("C:/ImagenesC/cubo/right.raw","r");
imagen4=(unsigned char*)malloc(an1*al1*3);
if(imagen==NULL){
printf("Error: No imagen");
return 0;
}
fread(imagen4,an1*al1*3,1,imagen);
fclose(imagen);
return 1;
}
int leerImagen5(){
FILE *imagen;
imagen=fopen("C:/ImagenesC/cubo/front.raw","r");
imagen5=(unsigned char*)malloc(an1*al1*3);
if(imagen==NULL){
printf("Error: No imagen");
return 0;
}
fread(imagen5,an1*al1*3,1,imagen);
fclose(imagen);
return 1;
}
int leerImagen6(){
FILE *imagen;
imagen=fopen("C:/ImagenesC/cubo/top.raw","r");
imagen6=(unsigned char*)malloc(an1*al1*3);
if(imagen==NULL){
printf("Error: No imagen");
return 0;
}
fread(imagen6,an1*al1*3,1,imagen);
fclose(imagen);
return 1;
}
void texturaI1(void)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, an1, al1, 0, GL_RGB, GL_UNSIGNED_BYTE, imagen1);
}
void texturaI2(void)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, an1, al1, 0, GL_RGB, GL_UNSIGNED_BYTE, imagen2);
}
void texturaI3(void)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, an1, al1, 0, GL_RGB, GL_UNSIGNED_BYTE, imagen3);
}
void texturaI4(void)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, an1, al1, 0, GL_RGB, GL_UNSIGNED_BYTE, imagen4);
}
void texturaI5(void)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, an1, al1, 0, GL_RGB, GL_UNSIGNED_BYTE, imagen5);
}
void texturaI6(void)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, an1, al1, 0, GL_RGB, GL_UNSIGNED_BYTE, imagen6);
}
void dibujaI1(void)//PISO
{
glDisable(GL_LIGHTING);
glColor3f(1,1,1);
glBegin(GL_QUADS);
glTexCoord3f(0.0, 1.0,0.0);
glVertex3f(-100,-100,100);
glTexCoord3f(0.0, 0.0,0.0);
glVertex3f(-100,-100,-100);
glTexCoord3f(1.0, 0.0,0.0);
glVertex3f(100,-100,-100);
glTexCoord3f(1.0, 1.0,0.0);
glVertex3f(100,-100,100);
glEnd();
glEnable(GL_LIGHTING);
}
void dibujaI2(void)//negx
{
glDisable(GL_LIGHTING);
glColor3f(1,1,1);
glBegin(GL_QUADS);
glTexCoord3f(0.0, 1.0,0.0);
glVertex3f(-100,-100,100);
glTexCoord3f(0.0, 0.0,0.0);
glVertex3f(-100,100,100);
glTexCoord3f(1.0, 0.0,0.0);
glVertex3f(-100,100,-100);
glTexCoord3f(1.0, 1.0,0.0);
glVertex3f(-100,-100,-100);
glEnd();
glEnable(GL_LIGHTING);
}
void dibujaI3(void)//negz
{
glDisable(GL_LIGHTING);
glColor3f(1,1,1);
glBegin(GL_QUADS);
glTexCoord3f(0.0, 1.0,0.0);
glVertex3f(100,-100,100);
glTexCoord3f(0.0, 0.0,0.0);
glVertex3f(100,100,100);
glTexCoord3f(1.0, 0.0,0.0);
glVertex3f(-100,100,100);
glTexCoord3f(1.0, 1.0,0.0);
glVertex3f(-100,-100,100);
glEnd();
glEnable(GL_LIGHTING);
}
void dibujaI4(void)
{
glDisable(GL_LIGHTING);
glColor3f(1,1,1);
glBegin(GL_QUADS);
glTexCoord3f(0.0, 1.0,0.0);
glVertex3f(-100,-100,-100);
glTexCoord3f(0.0, 0.0,0.0);
glVertex3f(-100,100,-100);
glTexCoord3f(1.0, 0.0,0.0);
glVertex3f(100,100,-100);
glTexCoord3f(1.0, 1.0,0.0);
glVertex3f(100,-100,-100);
glEnd();
glEnable(GL_LIGHTING);
}
void dibujaI5(void)
{
glDisable(GL_LIGHTING);
glColor3f(1,1,1);
glBegin(GL_QUADS);
glTexCoord3f(0.0, 1.0,0.0);
glVertex3f(100,-100,-100);
glTexCoord3f(0.0, 0.0,0.0);
glVertex3f(100,100,-100);
glTexCoord3f(1.0, 0.0,0.0);
glVertex3f(100,100,100);
glTexCoord3f(1.0, 1.0,0.0);
glVertex3f(100,-100,100);
glEnd();
glEnable(GL_LIGHTING);
}
void dibujaI6(void)
{
glDisable(GL_LIGHTING);
glColor3f(1,1,1);
glBegin(GL_QUADS);
glTexCoord3f(0.0, 1.0,0.0);
glVertex3f(-100,100,-100);
glTexCoord3f(0.0, 0.0,0.0);
glVertex3f(-100,100,100);
glTexCoord3f(1.0, 0.0,0.0);
glVertex3f(100,100,100);
glTexCoord3f(1.0, 1.0,0.0);
glVertex3f(100,100,-100);
glEnd();
glEnable(GL_LIGHTING);
}
void display(void)
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
GLfloat mat_specular[]={1.0,1.0,1.0,1.0};
GLfloat mat_shininess[]={50.0};
GLfloat mat_diff[]={1.0,0.5,0.0,0.5};
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_diff);
glPushMatrix();
glRotatef(a, 0, 1, 0);
glColor3f(1,1,1);
glPushMatrix();
texturaI1();
dibujaI1();
texturaI2();
dibujaI2();
texturaI3();
dibujaI3();
texturaI4();
dibujaI4();
texturaI5();
dibujaI5();
texturaI6();
dibujaI6();
glPopMatrix();
glPushMatrix();//TETERA
glColor3f(1.0, 1.0, 1.0);
glTranslated(0.0,10,0);
glutSolidTeapot(2);
glPopMatrix();
glPopMatrix();
a += 0.6;
glutSwapBuffers();
}
void myReshape(int w, int h)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective( 90.0, (GLdouble)w/(GLdouble)h, 0.1,200.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 5.0, 50.0,
0.0, 7.0, 0.0,
0.0, 1.0, 0.0);
glEnable(GL_NORMALIZE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
//glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL);
}
void myIdleFunc(void) {
glutPostRedisplay();
}
void inicio()
{
glEnable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION);
leerImagen1();
leerImagen2();
leerImagen3();
leerImagen4();
leerImagen5();
leerImagen6();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(800, 800);
glutCreateWindow("3D");
inicio();
glutReshapeFunc(myReshape);
glutDisplayFunc(display);
glutIdleFunc(myIdleFunc);
glClearColor(1.0, 1.0, 1.0, 1.0);
glutMainLoop();
return 0;
}
link
No hay comentarios:
Publicar un comentario