How to manually load a texture (C++ and DirectX)

Started by
3 comments, last by hughiecoles 15 years, 9 months ago
i'm working on loading MD2 models, but they usually come with textures in PCX format, and since LoadTextureFromFile doesn't load this format, how would I go about manualy loading and setting a texture?
--------------------------------------Not All Martyrs See Divinity, But At Least You Tried
Advertisement
Creating your own PCX loader would be a real pain as PCX is a RLE (run-length-encoded) format and you'd have to set a texture pixel by pixel but that's one solution.

Another solution is to use a supported-format texture.

A third alternative is a bit of a hack if you have to use the extension pcx but you don't care what's its real format is. Depending on your needs, it may help:

Load the PCX into a graphics editor and save it in a supported format (PNG, etc.) and save it where your DirectX app can find it.

Rename the <texture>.png to <texture>.pcx. It should still load. The DirectX texture loader doesn't care about the extension, just the content.

EDIT: A quick google search showed hits for third party code for loading various formats. You could grab some PCX loader code and modify it to suit.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

well its just a matter of the included model textures being in PCX, i guess i could convert them to a png and change the file path in the MD2 file

thanks

out of curiousity, how would you create a texture manually from anotehr file format, if you had the image already loaded? use D3DXCreateTexture(), then lock the newly created texture, and fill it manually?
--------------------------------------Not All Martyrs See Divinity, But At Least You Tried
Yeah, that would be the approach if (shudder) I were to try it.

Be sure to check the device caps to see if your card supports a dynamic texture if you're going to do that before you go to the trouble of writing a conversion routine.

EDIT: Read through the SDK info first if you're going to try it. There are several restrictions (dynamic textures can't be managed, etc.).

EDIT2: I don't think you'd have to modify the MD2 file. I'll bet your "fake" <texture>.png.pcx will load in most other apps.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

aha no, i think i'll go with changing the image type :) thanks alot
--------------------------------------Not All Martyrs See Divinity, But At Least You Tried

This topic is closed to new replies.

Advertisement