Skip to main content
gamedev.net
🔒 Locked

Diablo PCX loading problem

Started by eviltwigflipper Oct 31, 2004 at 12:25 PM 0 replies 950+ views
Original Post
eviltwigflipper
eviltwigflipper
I am currentlly working on a reconstruction of the Diablo EXE. Using my own code. The main premise of the project is to create a working Diablo game like the original. Blizzard has already said they would leave me alone if I didn't redistribute any copyrighted material(i.e. Diabdat.mpq, Diabloui.dll, etc), and didn't program any Battle.Net code in. I am having a problem with my PCX loading code.

// ImageManager.cpp

#include "diablo.h"

void ImageManager::LoadPCXfromMPQ(char *name)
{
	int width, height;

	int imgWidth, imgHeight, texFileLen, imgBufferPtr, i; 
    pcxHeader *pcxPtr; 
    unsigned char *imgBuffer, *pcxBufferPtr, *paletteBuffer,*imageData; 

	if(buffer == NULL) // Don't load the image again
		return;

	buffer = (unsigned char *)diabdat->GetFile(name);
	size = diabdat->lastreadsize;
	texFileLen = size;

	/* get the image dimensions */ 
    pcxPtr = (pcxHeader *)buffer; 
    imgWidth = pcxPtr->size[0] - pcxPtr->offset[0] + 1; 
    imgHeight = pcxPtr->size[1] - pcxPtr->offset[1] + 1; 

	/* image starts at 128 from the beginning of the buffer */ 
    imgBuffer = (unsigned char *)malloc( imgWidth * imgHeight ); 
    imgBufferPtr = 0; 
    pcxBufferPtr = &buffer[128]; 

    /* decode the pcx image */ 
    while( imgBufferPtr < (imgWidth * imgHeight) ) 
    { 
      if( *pcxBufferPtr > 0xbf ) 
      { 
        int repeat = *pcxBufferPtr++ & 0x3f; 
        for( i=0; i<repeat; i++ ) 
        { 
          imgBuffer[imgBufferPtr++] = *pcxBufferPtr; 
        } 
      } else { 
        imgBuffer[imgBufferPtr++] = *pcxBufferPtr; 
      } 
      pcxBufferPtr++; 
    } 

    /* read in the image palette */ 
    paletteBuffer = (unsigned char *)malloc( 768 ); 
    for( i=0; i<768; i++ ) 
      paletteBuffer = buffer[ texFileLen-768+i ]; 

    width=imgWidth; 
    height=imgHeight; 

    /* now create the OpenGL texture */ 
    { 
      int i, j; 
      imageData = (unsigned char *)malloc( width * height * 3 ); 
      for (j = 0; j < imgHeight; j++) 
      { 
        for (i = 0; i < imgWidth; i++) 
        { 
          imageData[3*(j * width + i)+0] 
            = paletteBuffer[ 3*imgBuffer[j*imgWidth+i]+0 ]; 
          imageData[3*(j * width + i)+1] 
            = paletteBuffer[ 3*imgBuffer[j*imgWidth+i]+1 ]; 
          imageData[3*(j * width + i)+2] 
            = paletteBuffer[ 3*imgBuffer[j*imgWidth+i]+2 ]; 
        } 
      } 
    } 
    /* cleanup */ 
    free( paletteBuffer ); 
    free( imgBuffer ); 
    glGenTextures(1, &texID); 
    glBindTexture(GL_TEXTURE_2D, texID); 
    glTexImage2D(GL_TEXTURE_2D,0,3,width,height,0,GL_RGB, GL_UNSIGNED_BYTE,imageData); 
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); 
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); 
}





This is how I am calling it:


boolean imagemangerssetup = false;
ImageManager *testimg;

/*
==========================================
    void SetupImageManagers(void)
==========================================
*/
void SetupImageManagers(void)
{
	char *errors;
	if(imagemangerssetup == true)
		return;

	testimg = new ImageManager;
	testimg->LoadPCXfromMPQ("ui_art\\title.pcx");

	imagemangerssetup = true;
}

/*
==========================================
    void UI_DrawBackground(GLuint texID)
==========================================
*/

void UI_DrawBackground(GLuint texID)
{
        glLoadIdentity();
	glBindTexture(GL_TEXTURE_2D, texID);
	glTranslatef(-1.5f,0.0f,-6.0f);		
	glBegin(GL_QUADS);							
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);			
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);			
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);			
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);		
	glEnd();
}

void NextFrame(void)
{
	SetupImageManagers(); // calls LoadPCXfromMPQ  and INIT the class
	UI_DrawBackground(testimg->texID);
}






My problem is the texture is not being applied to the square...it is just white. Any Ideas? Yes my MPQ loading functions work, I can view the PCX files externally.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.