Estoy intentando usar la libreria opengl para pponer una imgeb de fondo en un cubo y me sale verdad la imagen. el codigo es el suiguiente.
void Draw_Skybox(float x, float y, float z, float width, float height, float length)
{
// Center the Skybox around the given x,y,z position
x = x - width / 2;
y = y - height / 2;
z = z - length / 2;
// Draw Front side
glBindTexture(GL_TEXTURE_2D, SkyboxTexture[SKYFRONT]);
glBegin(GL_QUADS);
glTexCoord2f(1.0f, 0.0f); glVertex3f(x, y, z+length);
glTexCoord2f(1.0f, 1.0f); glVertex3f(x, y+height, z+length);
glTexCoord2f(0.0f, 1.0f); glVertex3f(x+width, y+height, z+length);
glTexCoord2f(0.0f, 0.0f); glVertex3f(x+width, y, z+length);
glEnd();
// Draw Back side
glBindTexture(GL_TEXTURE_2D, SkyboxTexture[SKYBACK]);
glBegin(GL_QUADS);
glTexCoord2f(1.0f, 0.0f); glVertex3f(x+width, y, z);
glTexCoord2f(1.0f, 1.0f); glVertex3f(x+width, y+height, z);
glTexCoord2f(0.0f, 1.0f); glVertex3f(x, y+height, z);
glTexCoord2f(0.0f, 0.0f); glVertex3f(x, y, z);
glEnd();
// Draw Left side
glBindTexture(GL_TEXTURE_2D, SkyboxTexture[SKYLEFT]);
glBegin(GL_QUADS);
glTexCoord2f(1.0f, 1.0f); glVertex3f(x, y+height, z);
glTexCoord2f(0.0f, 1.0f); glVertex3f(x, y+height, z+length);
glTexCoord2f(0.0f, 0.0f); glVertex3f(x, y, z+length);
glTexCoord2f(1.0f, 0.0f); glVertex3f(x, y, z);
glEnd();
// Draw Right side
glBindTexture(GL_TEXTURE_2D, SkyboxTexture[SKYRIGHT]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(x+width, y, z);
glTexCoord2f(1.0f, 0.0f); glVertex3f(x+width, y, z+length);
glTexCoord2f(1.0f, 1.0f); glVertex3f(x+width, y+height, z+length);
glTexCoord2f(0.0f, 1.0f); glVertex3f(x+width, y+height, z);
glEnd();
// Draw Up side
glBindTexture(GL_TEXTURE_2D, SkyboxTexture[SKYUP]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(x+width, y+height, z);
glTexCoord2f(1.0f, 0.0f); glVertex3f(x+width, y+height, z+length);
glTexCoord2f(1.0f, 1.0f); glVertex3f(x, y+height, z+length);
glTexCoord2f(0.0f, 1.0f); glVertex3f(x, y+height, z);
glEnd();
// Draw Down side
glBindTexture(GL_TEXTURE_2D, SkyboxTexture[SKYDOWN]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(x, y, z);
glTexCoord2f(1.0f, 0.0f); glVertex3f(x, y, z+length);
glTexCoord2f(1.0f, 1.0f); glVertex3f(x+width, y, z+length);
glTexCoord2f(0.0f, 1.0f); glVertex3f(x+width, y, z);
glEnd();
}
el codigo anterior esta en la funcion main y esta son las funciones definidas
void JPEG_Skybox(UINT textureArray[], LPSTR strFileName, int ID)
{
if(!strFileName) return;
tImageJPG *pBitMap = Load_JPEG(strFileName);
if(pBitMap == NULL) exit(0);
glGenTextures(1, &textureArray[ID]);
glBindTexture(GL_TEXTURE_2D, textureArray[ID]);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pBitMap->sizeX, pBitMap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pBitMap->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL _CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL _CLAMP_TO_EDGE);
if (pBitMap)
{
if (pBitMap->data)
{
free(pBitMap->data);
}
free(pBitMap);
}
}
//NEW//////////////////NEW//////////////////NEW//////////////////NEW////////////////
void JPEG_Texture(UINT textureArray[], LPSTR strFileName, int ID)
{
if(!strFileName) return;
tImageJPG *pBitMap = Load_JPEG(strFileName);
if(pBitMap == NULL) exit(0);
glGenTextures(1, &textureArray[ID]);
glBindTexture(GL_TEXTURE_2D, textureArray[ID]);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pBitMap->sizeX, pBitMap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pBitMap->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR_MIPMAP_LINEAR);
if (pBitMap)
{
if (pBitMap->data)
{
free(pBitMap->data);
}
free(pBitMap);
}
}
tImageJPG *Load_JPEG(const char *strfilename)
{
struct jpeg_decompress_struct cInfo;
tImageJPG *pImgData = NULL;
FILE *pFile;
if((pFile = fopen(strfilename, "rb")) == NULL)
{
MessageBox(hWnd, "Error loading jpg file.", "ERROR", MB_OK);
return NULL;
}
jpeg_error_mgr jerr;
cInfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cInfo);
jpeg_stdio_src(&cInfo, pFile);
pImgData = (tImageJPG*)malloc(sizeof(tImageJPG));
Decompress_JPEG(&cInfo, pImgData);
jpeg_destroy_decompress(&cInfo);
fclose(pFile);
return pImgData;
}
void Decompress_JPEG(jpeg_decompress_struct* cInfo, tImageJPG *pImgData)
{
jpeg_read_header(cInfo, TRUE);
jpeg_start_decompress(cInfo);
pImgData->rowSpan = cInfo->image_width * cInfo->num_components;
pImgData->sizeX = cInfo->image_width;
pImgData->sizeY = cInfo->image_height;
pImgData->data = new unsigned char[pImgData->rowSpan * pImgData->sizeY];
unsigned char** rowPtr = new unsigned char*[pImgData->sizeY];
for (int i = 0; i < pImgData->sizeY; i++)
rowPtr[i] = &(pImgData->data[i*pImgData->rowSpan]);
int rowsRead = cInfo->output_height-1;
while (cInfo->output_scanline < cInfo->output_height)
{
rowsRead -= jpeg_read_scanlines(cInfo, &rowPtr[rowsRead], cInfo->output_height - rowsRead);
}
delete [] rowPtr;
jpeg_finish_decompress(cInfo);
}
muxas gracia spor la ayuda