Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support dds/ prefix for dds images. #128

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions radiant/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,19 @@ Image* QERApp_LoadImage( void* environment, const char* name ){
StringOutputStream fullname( 256 );
fullname << m_name << '.' << name;
ArchiveFile* file = GlobalFileSystem().openFile( fullname.c_str() );

// also look for .dds image in dds/ prefix like Doom3 or DarkPlaces
if ( file == 0 && !string_compare( name, "dds" ) )
{
fullname.clear();
fullname << name << '/' << m_name << '.' << name;
file = GlobalFileSystem().openFile( fullname.c_str() );
}

if ( file != 0 ) {
// tell user which image file is found for the given texture path
globalOutputStream() << "Found image file: " << makeQuoted( fullname.c_str() ) << "\n";

m_image = table.loadImage( *file );
file->release();
}
Expand Down
17 changes: 17 additions & 0 deletions radiant/texwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,14 @@ class TextureCategoryLoadShader
};

void TextureDirectory_loadTexture( const char* directory, const char* texture ){
// Doom3-like dds/ prefix (used by DarkPlaces).
// When we list dds/textures/ folder,
// store the texture names without dds/ prefix.
if ( !strncmp( "dds/", directory, 4 ) )
{
directory = &directory[ 4 ];
}

const auto name = StringOutputStream( 256 )( directory, PathExtensionless( texture ) );

if ( texture_name_ignore( name.c_str() ) ) {
Expand Down Expand Up @@ -712,6 +720,9 @@ void TextureBrowser_ShowDirectory( const char* directory ){
globalOutputStream() << "Loading " << makeQuoted( directory ) << " wad file.\n";
LoadShaderVisitor visitor;
archive->forEachFile( Archive::VisitorFunc( visitor, Archive::eFiles, 0 ), "textures/" );

// Doom3-like dds/ prefix (used by DarkPlaces).
archive->forEachFile( Archive::VisitorFunc( visitor, Archive::eFiles, 0 ), "dds/textures/" );
}
else{
globalErrorStream() << "Attempted to load " << makeQuoted( directory ) << " wad file.\n";
Expand All @@ -732,6 +743,12 @@ void TextureBrowser_ShowDirectory( const char* directory ){
dirstring << "textures/" << directory;

Radiant_getImageModules().foreachModule( LoadTexturesByTypeVisitor( dirstring.c_str() ) );

// Doom3-like dds/ prefix (used by DarkPlaces).
dirstring.clear();
dirstring << "dds/textures/" << directory;

Radiant_getImageModules().foreachModule( LoadTexturesByTypeVisitor( dirstring.c_str() ) );
}
}

Expand Down
22 changes: 9 additions & 13 deletions tools/quake3/q3map2/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,20 +305,13 @@ const image_t *ImageLoad( const char *name ){
else if( path_set_extension( filename, ".dds" ); buffer = vfsLoadFile( filename ) )
{
LoadDDSBuffer( buffer.data(), buffer.size(), &pixels, &width, &height );
/* debug code */
#if 0
{
ddsPF_t pf;
DDSGetInfo( (ddsBuffer_t*) buffer, nullptr, nullptr, &pf );
Sys_Printf( "pf = %d\n", pf );
if ( width > 0 ) {
path_set_extension( filename, "_converted.tga" );
WriteTGA( "C:\\games\\quake3\\baseq3\\textures\\rad\\dds_converted.tga", pixels, width, height );
}
}
#endif
}
else if( path_set_extension( filename, ".ktx" ); buffer = vfsLoadFile( filename ) )
else if( sprintf( filename, "dds/%s.dds", name ); buffer = vfsLoadFile( filename ) )
{
/* also look for .dds image in dds/ prefix like Doom3 or DarkPlaces */
LoadDDSBuffer( buffer.data(), buffer.size(), &pixels, &width, &height );
}
else if( sprintf( filename, "%s.ktx", name ); buffer = vfsLoadFile( filename ) )
{
LoadKTXBufferFirstImage( buffer.data(), buffer.size(), &pixels, &width, &height );
}
Expand All @@ -330,6 +323,9 @@ const image_t *ImageLoad( const char *name ){
return nullptr;
}

/* tell user which image file is found for the given texture path */
Sys_FPrintf( SYS_VRB, "Loaded image: \"%s\"\n", name );

/* everybody's in the place, create new image */
image_t& image = *images.emplace_after( images.cbegin(), name, filename, width, height, pixels );

Expand Down