Well Whenever I use this code which I made myself, it only draws the texture of the other shape so obviosly these shapes are acting as one and I am wondering how do I give each shape its own caracteristics.
#include "Block.h"
Block::~Block()
{
glDeleteTextures(1, &TopTexture);
glDisable(GL_TEXTURE_2D);
}
Block::Block()
{
}
void Block::GetPositionX()
{
}
void Block::GetPositionY()
{
}
void Block::GetPositionZ()
{
}
void Block::GetRotation()
{
}
void Block::GetType()
{
}
void Block::SetPosition(float x,float y, float z)
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(x,y,z);
}
void Block::Rotation(float angle, float x, float y, float z)
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(angle,x,y,z);
}
void Block::Draw()
{
glMatrixMode(GL_MODELVIEW);
glEnable(GL_TEXTURE_2D);
// Draw a cube
float size = 20.f;
glBegin(GL_QUADS);
glBindTexture(GL_TEXTURE_2D, SideTexture);
glColor4f(1.f, 1.f, 1.f, 1.f);
glTexCoord2f(0, 0); glVertex3f(-size, -size, -size);
glTexCoord2f(0, 1); glVertex3f(-size, size, -size);
glTexCoord2f(1, 1); glVertex3f( size, size, -size);
glTexCoord2f(1, 0); glVertex3f( size, -size, -size);
glTexCoord2f(0, 0); glVertex3f(-size, -size, size);
glTexCoord2f(0, 1); glVertex3f(-size, size, size);
glTexCoord2f(1, 1); glVertex3f( size, size, size);
glTexCoord2f(1, 0); glVertex3f( size, -size, size);
glTexCoord2f(0, 0); glVertex3f(-size, -size, -size);
glTexCoord2f(0, 1); glVertex3f(-size, size, -size);
glTexCoord2f(1, 1); glVertex3f(-size, size, size);
glTexCoord2f(1, 0); glVertex3f(-size, -size, size);
glTexCoord2f(0, 0); glVertex3f(size, -size, -size);
glTexCoord2f(0, 1); glVertex3f(size, size, -size);
glTexCoord2f(1, 1); glVertex3f(size, size, size);
glTexCoord2f(1, 0); glVertex3f(size, -size, size);
glDisable(SideTexture);
glEnable(TopTexture);
glBindTexture(GL_TEXTURE_2D, TopTexture);
glColor4f(1.f, 1.f, 1.f, 1.f);
glTexCoord2f(0, 1); glVertex3f(-size, -size, size);
glTexCoord2f(0, 0); glVertex3f(-size, -size, -size);
glTexCoord2f(1, 0); glVertex3f( size, -size, -size);
glTexCoord2f(1, 1); glVertex3f( size, -size, size);
glBindTexture(GL_TEXTURE_2D, BottomTexture);
glColor4f(1.f, 1.f, 1.f, 1.f);
glTexCoord2f(0, 1); glVertex3f(-size, size, size);
glTexCoord2f(0, 0); glVertex3f(-size, size, -size);
glTexCoord2f(1, 0); glVertex3f( size, size, -size);
glTexCoord2f(1, 1); glVertex3f( size, size, size);
glEnd();
}
void Block::LoadTexture(BType BlockType)
{
std::string imagefileTop;
std::string imagefileSide;
std::string imagefileBottom;
if(BlockType == Grass) {imagefileTop = "GrassTop.jpg"; imagefileSide = "GrassSide.jpg"; imagefileBottom = "Dirt.jpg";}
if(BlockType == Dirt) {imagefileTop = "Dirt.jpg"; imagefileSide = "Dirt.jpg"; imagefileBottom = "Dirt.jpg";}
if(BlockType == Stone) {imagefileTop = "Stone.jpg"; imagefileSide = "Stone.jpg"; imagefileBottom = "Stone.jpg";}
if(BlockType == Wood) {imagefileTop = "WoodTop.jpg"; imagefileSide = "WoodSide.jpg"; imagefileBottom = "WoodTop.jpg";}
// Load an OpenGL texture.
// We could directly use a sf::Image as an OpenGL texture (with its Bind() member function),
// but here we want more control on it (generate mipmaps, ...) so we create a new one from the image pixels
TopTexture = 0;
{
sf::Image image;
if (!image.LoadFromFile("resources\\" + imagefileTop))
std::cout << "Could Not Load Texture";
glGenTextures(1, &TopTexture);
glBindTexture(GL_TEXTURE_2D, TopTexture);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, image.GetWidth(), image.GetHeight(), GL_RGBA, GL_UNSIGNED_BYTE, image.GetPixelsPtr());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
}
SideTexture = 0;
{
sf::Image image;
if (!image.LoadFromFile("resources\\" + imagefileSide))
std::cout << "Could Not Load Texture";
glGenTextures(1, &SideTexture);
glBindTexture(GL_TEXTURE_2D, SideTexture);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, image.GetWidth(), image.GetHeight(), GL_RGBA, GL_UNSIGNED_BYTE, image.GetPixelsPtr());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
}
BottomTexture = 0;
{
sf::Image image;
if (!image.LoadFromFile("resources\\" + imagefileBottom))
std::cout << "Could Not Load Texture";
glGenTextures(1, &BottomTexture);
glBindTexture(GL_TEXTURE_2D, BottomTexture);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, image.GetWidth(), image.GetHeight(), GL_RGBA, GL_UNSIGNED_BYTE, image.GetPixelsPtr());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
}
}
I call it like this in main..
Block Grass;
Grass.LoadTexture()
in the while loop
Grass.SetPosition(x,y,z); //Cube doesnt display inless this is in while..
Grass.Draw();