Poczatki, teksurowania

0

Mam problem z teksturowaniem, nie wyswietla mi jej poprawnie chodzi o to ze na 2 scianach jest ok a na drugich jakos rozmazane zamieszczam kod dodam tylko ze probowalem wszystkiego zamieszczam rowniez zdjecie o co chodzi.

#include <windows.h>
#include <gl/gl.h>
#include <gl/glut.h>
#include <iostream>
#include "glut.h"
#include <stdlib.h>
#include <corona.h>
#include "GameCamera.h"
#include "Vector.h"

using namespace std;
///////////////////
int mouseButton, state, pitch, roll,licznik=0;
CGameCamera gCamera;
GLuint TextureId[2]; //POTRZEBNE DO TEKSTUcY

/////////////////////
CVector spherePos(10, 10, 0);
CVector cubePos(0, 15, -15);
CVector teapotPos(40, 10, 10);
GLUquadricObj* q;
///////////////////
// wpółrzędne położenia obserwatora
GLdouble eyex = 0.0;
GLdouble eyey = 0.0;
GLdouble eyez =3.0;
// współrzędne punktu w którego kierunku jest zwrócony obserwator,
GLdouble centerx = 0;
GLdouble centery = 0;
GLdouble centerz =-100;
///////////////////////
const double dtr = M_PI/180.0;
const double motionSpeed = 5;
const double rotationSpeed = 1;
/////////////////////////
struct PointF{
GLfloat x,y,z;
};
////////////////////////////
PointF p1 = {-5.0f,5.0f, -5.0f},
p2 = {-5.0f,5.0f, 5.0f},
p3 = { 5.0f,5.0f, 5.0f},
p4 = { 5.0f,5.0f, -5.0f},
p5 = {-5.0f,-5.0f,-5.0f},
p6 = {-5.0f,-5.0f, 5.0f},
p7 = { 5.0f,-5.0f, 5.0f},
p8 = { 5.0f,-5.0f,-5.0f};
////////////////////////////////////
bool LoadTexture(char *_filename){
// Load texture
corona::Image *TextureImage = corona::OpenImage(_filename);
if (TextureImage)
{
glGenTextures(2, &TextureId[licznik]);
glBindTexture(GL_TEXTURE_2D, TextureId[licznik]);
// get the format of image
GLuint TextureFormat;
switch (TextureImage->getFormat())
{
case corona:
TextureImage = ConvertImage(TextureImage, corona::PF_R8G8B8A8);
TextureFormat = GL_RGBA; break;

        case corona::PF_R8G8B8A8:
            TextureFormat = GL_RGBA; break;

        case corona::PF_B8G8R8:
            TextureImage = ConvertImage(TextureImage, corona::PF_R8G8B8);
            TextureFormat = GL_RGB; break;
            
        case corona::PF_R8G8B8:
            TextureFormat = GL_RGB; break;
            
        case corona::PF_I8: // for example gif - convert to RGB
            TextureImage = ConvertImage(TextureImage, corona::PF_R8G8B8);
            TextureFormat = GL_RGB; break;
            
        default:
            MessageBox(NULL,"Unknown graphics format.","ERROR",MB_OK|MB_ICONEXCLAMATION);
            return false;
    }
	// Flip image
	FlipImage(TextureImage, corona::CA_X);
	// Generate The Texture
	glTexImage2D(GL_TEXTURE_2D, 0, TextureFormat, TextureImage->getWidth(), TextureImage->getHeight(), 0, TextureFormat, GL_UNSIGNED_BYTE, TextureImage->getPixels());
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);	// Linear Filtering
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	
	licznik++;
	
	delete TextureImage;
}
else
{
    MessageBox(NULL,"Failed open graphics file!","ERROR",MB_OK|MB_ICONEXCLAMATION);
    return false;
}

return true;

}
void RysujSciane(const PointF& p1, const PointF& p2, const PointF& p3, const PointF& p4){
glBegin(GL_QUADS);
glTexCoord2f(p1.x, p1.y);
glVertex3f(p1.x, p1.y, p1.z);
glTexCoord2f(p2.x, p2.y);
glVertex3f(p2.x, p2.y, p2.z);
glTexCoord2f(p3.x, p3.y);
glVertex3f(p3.x, p3.y, p3.z);
glTexCoord2f(p4.x, p4.y);
glVertex3f(p4.x, p4.y, p4.z);
glEnd();
};
void Keyboard(unsigned char key, int x, int y){
int mod = glutGetModifiers();

switch ( key )
{
//exit program
case 27:
	exit( EXIT_SUCCESS );
	break;
case '+':
	eyez += 0.1;
	break;
case '-':
	eyez -= 0.1;
	break;
}  
 

}
void KeyboardSpecial(int key, int x, int y){
switch (key)
{
case GLUT_KEY_LEFT:
gCamera.moveLeftRight(-motionSpeed);
break;
case GLUT_KEY_RIGHT:
gCamera.moveLeftRight(motionSpeed);
break;
case GLUT_KEY_UP:
gCamera.moveForward(motionSpeed);
break;
case GLUT_KEY_DOWN:
gCamera.moveForward(-motionSpeed);
break;
}
}
void mouseClick(int button, int state, int x, int y){
if ( mouseButton == GLUT_LEFT_BUTTON && state == GLUT_DOWN )
{
pitch = y;
roll = x;
}
::mouseButton = button;
::state = state;
}
void mouseMove(int x, int y){
if ( mouseButton == GLUT_LEFT_BUTTON && state == GLUT_DOWN )
{
gCamera.setPitch( -(y - pitch)dtrrotationSpeed );
gCamera.setRoll( -(x - roll)dtrrotationSpeed );
}
pitch = y;
roll = x;
}
bool Init(){
glClearColor(0.2f, 0.2f, 0.5f, 1.0f);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, 1.0, 0.1, 1000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glutMouseFunc(mouseClick);
glutMotionFunc(mouseMove);
glutKeyboardFunc(Keyboard);
glutSpecialFunc(KeyboardSpecial);
glutFullScreen();
if (!LoadTexture("tekstury/image.jpg")) return false;
if (!LoadTexture("tekstury/image1.jpg")) return false;
glEnable(GL_TEXTURE_2D);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

return true;

}
GLfloat kat;
void Render(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
kat+=0.2;

glPushMatrix();
gluLookAt( eyex, eyey, eyez, centerx, centery, centerz, 0, 1, 0 );

glRotatef(kat,0.0f,1.0f,0.0f );

glBindTexture(GL_TEXTURE_2D, TextureId[0]);
glColor3f(0.0f, 1.0f, 1.0f);
RysujSciane(p1, p2, p6, p5);
glColor3f(1.0f, 0.0f, 0.0f);
RysujSciane(p4, p8, p7, p3);
glColor3f(0.0f, 1.0f, 0.5f);
RysujSciane(p1, p5, p8, p4);
glColor3f(0.0f, 1.0f, 1.0f);
RysujSciane(p3, p7, p6, p2);
glColor3f(1.0f, 1.0f, 0.0f);
RysujSciane(p1, p4, p3, p2);
//podloga
glBindTexture(GL_TEXTURE_2D, TextureId[1]);

	glColor3f(0.1f, 0.1f, 0.1f);
	RysujSciane(p5, p6, p7, p8);
glPopMatrix();
glFlush();
glutSwapBuffers();

}
void Idle(){
Render();
}
int main (int argc, char **argv){
glutInitDisplayMode(GLUT_DOUBLE);
glutCreateWindow("jamal");
Init();
glutIdleFunc(Idle);
glutDisplayFunc(Render);
glutMainLoop();
return EXIT_SUCCESS;
}

0

Tak na oko mogę powiedzieć, że nieprawidłowe glTexCoord.

1 użytkowników online, w tym zalogowanych: 0, gości: 1