Jump to content
  • Advertisement
Sign in to follow this  
tscott1213

MDL Embedded Textures

This topic is 5049 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey gang, I am going through Valve's MDL viewer code and I am having some trouble understanding the function to load and format the embedded textures. Specifically, in the following function can somone explain to me what is going on in the 'for' loop involving the pix1, pix2, pix3, pix4 variables and the use of the row1,row2,col1,col2 variables, etc. Thanks for the help. Heres the function... (also, as an aside, is there a way for me to paste in this code in a cleaner format?) void StudioModel::UploadTexture(mstudiotexture_t *ptexture, byte *data, byte *pal) { //determine new width & height to convert texture to power of 2 for (int outwidth = 1; outwidth < ptexture->width; outwidth <<= 1) ; for (int outheight = 1; outheight < ptexture->height; outheight <<= 1) ; if (outheight > 256) outheight = 256; if (outwidth > 256) outwidth = 256; //allocate memory for a 32 bit (4 byte) RGB image byte *tex, *out; tex = out = (byte *)malloc( outwidth * outheight * 4); int col1[256], col2[256]; for (int i = 0; i < outwidth; i++) { col1 = (i + 0.25) * (ptexture->width / (float)outwidth); col2 = (i + 0.75) * (ptexture->width / (float)outwidth); } int row1[256], row2[256]; for (int i = 0; i < outheight; i++) { row1 = (int)((i + 0.25) * (ptexture->height / (float)outheight)) * ptexture->width; row2 = (int)((i + 0.75) * (ptexture->height / (float)outheight)) * ptexture->width; } //scale down and convert to 32bit RGB byte *pix1, *pix2, *pix3, *pix4; for (int i=0 ; i<outheight ; i++) { for (int j=0 ; j<outwidth ; j++, out += 4) { pix1 = &pal[data[row1 + col1[j]] * 3]; pix2 = &pal[data[row1 + col2[j]] * 3]; pix3 = &pal[data[row2 + col1[j]] * 3]; pix4 = &pal[data[row2 + col2[j]] * 3]; out[0] = (pix1[0] + pix2[0] + pix3[0] + pix4[0])>>2; out[1] = (pix1[1] + pix2[1] + pix3[1] + pix4[1])>>2; out[2] = (pix1[2] + pix2[2] + pix3[2] + pix4[2])>>2; out[3] = 0xFF; } } glBindTexture( GL_TEXTURE_2D, g_texnum ); glTexImage2D( GL_TEXTURE_2D, 0, 3/*??*/, outwidth, outheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex ); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // ptexture->width = outwidth; // ptexture->height = outheight; ptexture->index = g_texnum; g_texnum++; free( tex ); } [Edited by - tscott1213 on November 27, 2004 12:58:52 PM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!