|
dev.gamez.lv Latvian Game Developers Community
|
View previous topic :: View next topic |
Author |
Message |
jr200
Joined: 19 Apr 2008 Posts: 6
|
Posted: Wed Jun 25, 2008 10:32 am Post subject: PHYSFS texturu ielādēšana |
|
Gribēju uztaisīt tā kad zip arhīvā, piemēram, myzip.zip stāv pāris bildītes. un tad tas ielādēt izmantojot PhysFs. Bet kā lai `PHYSFS_sint64' pārveido par `const char*'. Tā arī ir vienīgā problēma. Kopumā errors ir šāds "invalid conversion from `PHYSFS_sint64' to `const char*' "
Code: |
char *myBuf;
PHYSFS_init(NULL);
PHYSFS_mount("myzip.zip", "/Data/", 1);
PHYSFS_File* f = PHYSFS_openRead("/fails.bmp");
myBuf = new char[PHYSFS_fileLength(f)];
const char* texture=PHYSFS_read(f, myBuf, 1, PHYSFS_fileLength(f));
if ((!LoadGLTexture(texture)))
{
return FALSE;
}
PHYSFS_close(f);
|
|
|
Back to top |
|
|
snake5 Indago dalībnieks
Joined: 27 Jun 2007 Posts: 2590
|
Posted: Wed Jun 25, 2008 10:38 am Post subject: |
|
RTFM :D
nav gluži īstās funkcijas, bet
http://docs.taoframework.com/Tao.PhysFs/Tao.PhysFs.Fs.PHYSFS_read_overloads.html
visas atgriež objektu skaitu, nevis nosaukumu
gan jau tev mybufā tā tekstūra būs
P.S.
ja LoadGLTexture prasa faila nosaukumu, to tev te nemeklēt ;)
btw, te ar OpenGL nekāda sakara nav _________________ "There are two choices here: "looks good" and "realism"." -- Paul Nettle |
|
Back to top |
|
|
jr200
Joined: 19 Apr 2008 Posts: 6
|
Posted: Wed Jun 25, 2008 12:31 pm Post subject: |
|
Varbūt kurš ir krāmējies ar šim lietām varētu parādīt kādu paraugu kā no zip arhīva ielādēt textūras. Vai arī ieteikt ko citu. |
|
Back to top |
|
|
bubu Indago Uzvarētājs
Joined: 23 Mar 2004 Posts: 3223 Location: Riga
|
Posted: Wed Jun 25, 2008 2:01 pm Post subject: |
|
šņak - ja nezini par ko ir runa, varbūt nepostē neko. Linku uz .NET wraperi iedevi. No tevis tik spams un spams.
jr200:
PHYSFS_read atgriež nevis pašus datus (const char*), bet gan datus ielasa tajā padotajā buferī (otrajā argumentā):
Code: | PHYSFS_init(argv[0]);
PHYSFS_mount("myzip.zip", "/Data/", 1);
PHYSFS_File* f = PHYSFS_openRead("/fails.bmp");
std::vector<char> buffer(PHYSFS_fileLength(f));
if (PHYSFS_read(f, &buffer[0], buffer.size(), 1) == 1)
{
// .. te izmanto &buffer[0] pointeri, kas saturēs visus faila datus.
// ...
}
else
{
// kļūda - nesanāca nolasīt.
}
PHYSFS_close(f); |
Lasi uzmanīgāk dokumentāciju! http://icculus.org/physfs/docs/html/ |
|
Back to top |
|
|
snake5 Indago dalībnieks
Joined: 27 Jun 2007 Posts: 2590
|
Posted: Wed Jun 25, 2008 3:30 pm Post subject: |
|
tak es zinu uz ko es linku iedevu!
c++ versiju tik ātri nesameklēju, bet, tagad paskatījos un redzu, ka gan argumenti, gan atgrieztās vērtības ir tie paši!
tad who cares vai c++ vai c#, ja tā informācija, kura tur atrodas, nav atkarīga no valodas? _________________ "There are two choices here: "looks good" and "realism"." -- Paul Nettle |
|
Back to top |
|
|
jr200
Joined: 19 Apr 2008 Posts: 6
|
Posted: Thu Jun 26, 2008 6:24 pm Post subject: |
|
Isteniibas viss ir daudz vienkaarsaak nekaa saakumaa biju domaajis. Faila dati glabaajas bufferaa. Ar so programmu man izdevaas mieriigi nolasiit datus no *.txt faila.
Code: |
char *myBuf;
PHYSFS_init(argv[0]);
PHYSFS_mount("myzip.zip", "/", 1);
PHYSFS_File* f = PHYSFS_openRead("/text.txt");
myBuf = new char[PHYSFS_fileLength(f)];
cout << myBuf << endl;
|
Tagat atliek izdomaat kaa 'char' paarveidot par 'UINT'. Saadaa veidaa viss it kaa buutu kartiibaa, bet kad palaiz programmu textuura nav ielaadeejusies.
Code: |
UINT myBuf;
GLuint texture[6];
PHYSFS_init(argv[0]);
PHYSFS_mount("myzip.zip", "/Data/", 1);
PHYSFS_File* f = PHYSFS_openRead("fails.bmp");
myBuf = PHYSFS_fileLength(f);
texture[0]=myBuf;
PHYSFS_close(f);
|
|
|
Back to top |
|
|
bubu Indago Uzvarētājs
Joined: 23 Mar 2004 Posts: 3223 Location: Riga
|
Posted: Thu Jun 26, 2008 7:25 pm Post subject: |
|
Īstenībā viss ir drusku sarežģītāk nekā tev liekās.
Izskatās, ka tev nav saprašana par to, kā notiek tekstūras izveidošana OpenGL'ā.
Tas GLuint ir tikai handlis. Unikāls skaitlis, kas identificē tekstūru. Tajā tu nevari tā vienkārši ierakstīt (piešķirt) veselu bildi.
Lai ielādētu pašu bildi (tekstūras pikseļus) vajag vispirms uztaisīt tekstūru (glGenTextures), padarīt to aktīvu (glBindTexture) un tad aizsūtīt pašus pikseļu datus uz videokarti (glTexImage2D).
Tu nevari pa tiešo "ielasīt" tekstūras handli no faila. Handli var tikai izveidot ar glGenTextures funkciju. PhysFS var izmantot, lai dabūtu tos datus, kuri jāpadot glTexImage2D funkcijai un nekam vairāk. Tieši to es savā piemērā uzrakstīju - ielādēju bildes datus iekš buffer vektora (C++ dinamiska masīva wraperis), kurus tālāk ir jāpadod glTexImage2D fjai.
Še palasi:
http://www.nullterminator.net/gltexture.html
http://gpwiki.org/index.php/OpenGL:Tutorials:Tutorial_Framework:Texture_Mapping
Pie tam ņem vērā, ka OpenGL nesaprot nekādus bilžu formātus (bmp, png, jpg, tga, ...). OpenGL sagaida tikai plikus bildes pikseļus (ok, vēl ir kompresētie formāti, bet tā ir cita opera). Tev pašam būs jānolasa tie pikseļi pareizā formātā atmiņā, lai padotu glTexImage2D funkcijai.
Lai lieki nečakarētos izmanto kādu vienkāršāku OpenGL freimworku (vai arī bilžu manipulēšanas bibliotēku), kas tev to nodrošinās.
Iesaku paskatīties uz http://glfw.sourceforge.net/
Vēl labs ir http://www.libsdl.org/ (ar daudz vairāk iespējām)
Ja vajag tikai vienkāršu bilžu ielādi, nevis veselu freimworku, tad var, piemēram, paņemt šo: http://gpwiki.org/index.php/LoadTGACpp
Vai arī ko šādu: http://corona.sourceforge.net/ (tas nekas, ka vecs datums - pati bibliotēka labi dara, kas tai jādara).
Vai arī ko advancētāku ar vairāk iespējām: http://freeimage.sourceforge.net/ |
|
Back to top |
|
|
jr200
Joined: 19 Apr 2008 Posts: 6
|
Posted: Sun Jun 29, 2008 9:06 am Post subject: |
|
Ja kaada interesee es varu iedot gala rezuultaatu kaa to var izdariit. Bet taa kaa programma ir atrii sakiileeta, tai veel vajag vairaakus uzlabojumus.
Code: |
char* myBuf;
GLenum texture_format;
GLint nOfColors;
PHYSFS_init(NULL);
PHYSFS_mount("myzip.zip", "/", 1);
PHYSFS_File* f = PHYSFS_openRead("/fails.bmp");
myBuf = new char[PHYSFS_fileLength(f)];
PHYSFS_read(f, &myBuf[0], 1, PHYSFS_fileLength(f));
PHYSFS_sint64 file_size = PHYSFS_fileLength(f);
SDL_RWops *rw = SDL_RWFromMem(myBuf, file_size);
SDL_Surface *surface = SDL_LoadBMP_RW(rw, 1);
// get the number of channels in the SDL surface
nOfColors = surface->format->BytesPerPixel;
if (nOfColors == 4) // contains an alpha channel
{
if (surface->format->Rmask == 0x000000ff)
texture_format = GL_RGBA;
else
texture_format = GL_BGRA;
} else if (nOfColors == 3) // no alpha channel
{
if (surface->format->Rmask == 0x000000ff)
texture_format = GL_RGB;
else
texture_format = GL_BGR;
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h,
0, texture_format, GL_UNSIGNED_BYTE, surface->pixels );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glMatrixMode(GL_MODELVIEW);
SDL_FreeSurface(surface);
PHYSFS_close(f);
|
|
|
Back to top |
|
|
bubu Indago Uzvarētājs
Joined: 23 Mar 2004 Posts: 3223 Location: Riga
|
Posted: Sun Jun 29, 2008 9:42 am Post subject: |
|
Tu tur pamatīgi atmiņu līko - neatbrīvo ne myBuf, ne arī rw mainīgos. Tāpēc es jau tev devu piemēru ar std::vector izmantošanu new char vietā! Lietojot std::vector nebūtu jāuztraucas par atmiņas atbrīvošanu - tas to darītu pats automātiski.
Katrā ziņā, ja tu izmanto SDL, tad var rakstīt daudz īsāk un optimālāk. Šo te visu:
Code: | PHYSFS_File* f = PHYSFS_openRead("/fails.bmp");
myBuf = new char[PHYSFS_fileLength(f)];
PHYSFS_read(f, &myBuf[0], 1, PHYSFS_fileLength(f));
PHYSFS_sint64 file_size = PHYSFS_fileLength(f);
SDL_RWops *rw = SDL_RWFromMem(myBuf, file_size); |
var aizstāt ar vienu rindiņu:
Code: | SDL_RWops* rw = PHYSFSRWOPS_openRead("/fails.bmp"); |
Un attiecīgi pie faila aizvēršanas rakstīt:
PHYSFSRWOPS_openRead funkciju var atrast extras/physfsrwops.h/c failos physfs sourcē. Abus failus iekļauj savā projektā un jābūt ok. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|