я попытался нарисовать куб с различными текстурами на каждой стороне, используя OpenGL
но сейчас …
в чем проблема?!
после добавления различных текстур к каждой грани куба:
вот мой код:
> #include "stdafx.h"> #include <stdio.h>
> #include <stdlib.h>
> #include <gl/glut.h>
> #include <iostream>
>
> static GLuint tex[6]; static GLdouble angle = 1;
>
> void init() { glClearColor(0,0,0,1); glEnable(GL_TEXTURE_2D); }
> GLuint loadtexture(const char *filename,int width,int height) {
> GLuint texture; unsigned char *data; FILE *f; f =
> fopen(filename,"rb"); if(!f) return 0; data = (unsigned
> char*)malloc(width*height*3); fread(data,width*height*3,1,f);
> fclose(f); glGenTextures(1,&texture);
> glBindTexture(GL_TEXTURE_2D,texture);
> gluBuild2DMipmaps(GL_TEXTURE_2D,3,width,height,GL_RGB,GL_UNSIGNED_BYTE,data);
> free(data); return (texture); } void display() { glPushMatrix();
> glClear(GL_COLOR_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT);
> glGenTextures(1,&tex[0]); glGenTextures(1,&tex[1]);
> glGenTextures(1,&tex[2]); glGenTextures(1,&tex[3]);
> glGenTextures(1,&tex[4]); glGenTextures(1,&tex[5]); tex[0] =
> loadtexture("E:/1.raw",8,8); tex[1] = loadtexture("E:/2.raw",16,16);
> tex[2] = loadtexture("E:/3.raw",32,32); tex[3] =
> loadtexture("E:/4.raw",64,64); tex[4] =
> loadtexture("E:/5.raw",256,256); tex[5] =
> loadtexture("E:/6.raw",512,512); glRotatef(angle,1.0,0.0,0.0);
> glRotatef(angle,0.0,1.0,0.0); glRotatef(angle,0.0,0.0,1.0);
> glPushMatrix(); glColor3f(1.0, 1.0, 1.0);
> glBindTexture(GL_TEXTURE_2D,tex[0]); glBegin(GL_QUADS);
> glTexCoord2d(0.0f,0.0f);glVertex3f(-0.5f, -0.5f, 0.5f);
> glTexCoord2d(0.0f,0.5f);glVertex3f( 0.5f, -0.5f, 0.5f);
> glTexCoord2d(0.5f,0.0f);glVertex3f( 0.5f, 0.5f, 0.5f);
> glTexCoord2d(0.5f,0.5f);glVertex3f( -0.5f, 0.5f, 0.5f); glEnd();
> glPopMatrix(); glPushMatrix(); glColor3f(1.0, 1.0, 1.0);
> glBindTexture(GL_TEXTURE_2D,tex[1]); glBegin(GL_QUADS);
> glTexCoord2d(0.0f,0.0f);glVertex3f( -0.5f, -0.5f, -0.5f);
> glTexCoord2d(0.5f,0.0f);glVertex3f( -0.5f, 0.5f, -0.5f);
> glTexCoord2d(0.0f,0.5f);glVertex3f( 0.5f, 0.5f, -0.5f);
> glTexCoord2d(0.5f,0.5f);glVertex3f( 0.5f, -0.5f, -0.5f); glEnd();
> glPopMatrix(); glPushMatrix(); glColor3f(1.0, 1.0, 1.0);
> glBindTexture(GL_TEXTURE_2D,tex[2]); glBegin(GL_QUADS);
> glTexCoord2d(0.0f,0.0f);glVertex3f( -0.5f, -0.5f, 0.5f);
> glTexCoord2d(0.5f,0.5f);glVertex3f( -0.5f, 0.5f, 0.5f);
> glTexCoord2d(0.0f,0.0f);glVertex3f( -0.5f, 0.5f, -0.5f);
> glTexCoord2d(0.5f,0.0f);glVertex3f( -0.5f, -0.5f, -0.5f); glEnd();
> glPopMatrix(); glPushMatrix(); glColor3f(1.0, 1.0, 1.0);
> glBindTexture(GL_TEXTURE_2D,tex[3]); glBegin(GL_QUADS);
> glTexCoord2d(0.0f,0.0f);glVertex3f( 0.5f, -0.5f, -0.5f);
> glTexCoord2d(0.5f,0.5f);glVertex3f( 0.5f, 0.5f, -0.5f);
> glTexCoord2d(0.0f,0.5f);glVertex3f( 0.5f, 0.5f, 0.5f);
> glTexCoord2d(0.5f,0.0f);glVertex3f( 0.5f, -0.5f, 0.5f); glEnd();
> glPopMatrix(); glPushMatrix(); glColor3f(1.0,1.0,1.0);
> glBindTexture(GL_TEXTURE_2D,tex[4]); glBegin(GL_QUADS);
> glTexCoord2d(0.0f,0.0f);glVertex3f( -0.5f, 0.5f, 0.5f);
> glTexCoord2d(0.0f,0.5f);glVertex3f( 0.5f, 0.5f, 0.5f);
> glTexCoord2d(0.5f,0.5f);glVertex3f( 0.5f, 0.5f, -0.5f);
> glTexCoord2d(0.5f,0.0f);glVertex3f( -0.5f, 0.5f, -0.5f); glEnd();
> glPopMatrix(); glPushMatrix(); glColor3f(1.0,1.0,1.0);
> glBindTexture(GL_TEXTURE_2D,tex[5]); glBegin(GL_QUADS);
> glTexCoord2d(0.5f,0.5f);glVertex3f( -0.5f, -0.5f, 0.5f);
> glTexCoord2d(0.5f,0.0f);glVertex3f( -0.5f, -0.5f, -0.5f);
> glTexCoord2d(0.0f,0.5f);glVertex3f( 0.5f, -0.5f, -0.5f);
> glTexCoord2d(0.0f,0.0f);glVertex3f( 0.5f, -0.5f, 0.5f); glEnd();
> glPopMatrix(); glPopMatrix(); glutSwapBuffers(); angle+=0.09;
> glutPostRedisplay(); } void main(int argc, char ** argv) {
> glutInit(& argc,argv); glutInitDisplayMode(GLUT_DOUBLE);
> glutInitWindowSize(500,500); glutInitWindowPosition(100,100);
> glutCreateWindow("moka'ab"); init(); glutDisplayFunc(display);
> glutMainLoop(); }
что случилось?
Помогите мне, пожалуйста
glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL);
перед нанесением следует это исправить!