gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Texturing on polys (not quite as n00bish as my other topics)

#111209 - djmcbell - Mon Dec 04, 2006 10:11 pm

I've been using the Drunken Coder's code for creating textured cubes that comes with the DevKitPro. Basically, it includes code on how to make a cube with the Drunken Coder's texture on it.

I'm wondering how I go about making my own textures. I've created the necessary PCX in Paint Shop Pro and tried converting it how I converted my 2D backdrops using GFX2GBA, but the result is a mess. It seems that either the files are messed, or they're looking in totally the wrong place in memory.

So, I'm wondering how it would be best to go about converting a 128x128 texture (or whatever size - I'd love a 192x192 but doubt that'd be possible) with a 256 colour palette, and putting it into the code. Nothing in depth, just a quick step-by-step guide so I can see where I'm going wrong.

Thanks again for putting up with my n00bish-ness, maybe one day I'll find the brain the Wizard of Oz kept saying I had...

#111217 - ProblemBaby - Mon Dec 04, 2006 11:04 pm

Texture memory is linear not tiles. select "no tiling".

#111292 - Sausage Boy - Tue Dec 05, 2006 2:52 pm

I wrote a great tool for converting textures to most of the different formats the DS supports. While gfx2gba can easily convert to the raw format, it's just not the right tool for the job. You can score a copy at http://www.gasp.boxgamex.net/?p=21 .
_________________
"no offense, but this is the gayest game ever"

#111294 - FireSlash - Tue Dec 05, 2006 3:03 pm

You can load PCX files directly.

Code from LumiDS:
Code:
   sImage pcx;               
   FAT_FILE * pFile;
   long lSize;
   char * buffer;

   pFile = FAT_fopen ("/data/lumiDS/base/logo_top.pcx","r");
   if (!pFile) return false;
   FAT_fseek (pFile , 0 , SEEK_END);
   lSize = FAT_ftell (pFile);
   FAT_fseek(pFile, 0, SEEK_SET);

   // allocate memory to contain the whole file.
   buffer = (char*) malloc (lSize);
   if (!buffer) return false;

   // copy the file into the buffer.
   FAT_fread (buffer,1,lSize,pFile);

   loadPCX((u8*)buffer, &pcx);

   image8to16(&pcx);

   glGenTextures(1, &textures[0]);
   glBindTexture(0, textures[0]);
   glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_256 , TEXTURE_SIZE_256, 0, TEXGEN_TEXCOORD, pcx.data8);

   imageDestroy(&pcx);

   FAT_fclose (pFile);
   free (buffer);

_________________
FireSlash.net

#111382 - dannyboy - Wed Dec 06, 2006 2:14 am

Here's how I do it using GBFS with texture.h and texture.cpp.

Code:
/////////////////////////// Texture.h /////////////////////////
#ifndef TEXTURE_H
#define TEXTURE_H

// Needed to load pcx files
#include <nds/arm9/image.h>
#include <nds/arm9/trig_lut.h>

#include <gbfs.h>
extern const GBFS_FILE  data_gbfs;

class CTexture
{
    public:
        void LoadTextureSet1();
        void LoadTextureSet2();
    private:
        void Load(int index, sImage pcx, int Size);
        int   texture[15];         // Pointer for i Textures
};

#endif
/////////////////////////// Texture.h /////////////////////////

/////////////////////////// Texture.cpp /////////////////////////
#include "Texture.h"

void CTexture::Load(int index, sImage pcx, int Size) // Loads actual texture
{
    image8to16trans(&pcx, 0);
   glGenTextures(1, &texture[index]);
   glBindTexture(0, texture[index]);
   glTexImage2D(0, 0, GL_RGB, Size , Size, 0, TEXGEN_TEXCOORD | GL_TEXTURE_WRAP_S | GL_TEXTURE_WRAP_T, pcx.data8);
   imageDestroy(&pcx);
}

void CTexture::LoadTextureSet1()
{
    sImage pcx;

    glResetTextures();      // Clears all texture memory

    loadPCX((u8*)gbfs_get_obj(&data_gbfs, "zero.pcx", NULL), &pcx);
    Load(0, pcx, TEXTURE_SIZE_64);

    loadPCX((u8*)gbfs_get_obj(&data_gbfs, "one.pcx", NULL), &pcx);
    Load(1, pcx, TEXTURE_SIZE_128);

    loadPCX((u8*)gbfs_get_obj(&data_gbfs, "two.pcx", NULL), &pcx);
    Load(2, pcx, TEXTURE_SIZE_64);

    loadPCX((u8*)gbfs_get_obj(&data_gbfs, "three.pcx", NULL), &pcx);
    Load(3, pcx, TEXTURE_SIZE_32);
}
/////////////////////////// Texture.cpp /////////////////////////