
Krótka notatka, jak szybko zaimportować plik formatu graficznego (JPG, PNG, ...) na użytek aplikacji
OpenGL.
corona::Image *img = corona::OpenImage(filename);
if (img)
{
...
}
img->getWidth(); img->getHeight();
switch(img->getFormat())
{
case corona::PF_B8G8R8A8:
img = ConvertImage(img, corona::PF_R8G8B8A8);
format = GL_RGBA; break;
case corona::PF_R8G8B8A8:
format = GL_RGBA; break;
case corona::PF_R8G8B8:
format = GL_RGB; break;
...
}
img->getPixels();
FlipImage(TexImage, corona::CA_X);
glTexImage2D(GL_TEXTURE_2D, 0, format, img->getWidth(), img->getHeight(), 0, format, GL_UNSIGNED_BYTE, img->getPixels());
delete img;
Do ściągnięcia przykładowy program korzystający z biblioteki Corona. Uwaga! Pamiętaj o rozdzielczości obrazu będącej iloczynem dwóch potęg liczby 2. (wymagane przez glTexImage2D). opengl_jpg.zip (9 Kb)
Jak szybko dodać obsługę plików dźwiękowych (WAV, OGG, FLAC, MP3, MOD, AIFF...) ?
Np. dzięki bibliotece
Audiere (Ah Dee Air).
Dostępną dla Dev-C++ również jako pakiet dostępny na stronach G-Productions albo DevPacks.org.
Krótki tutorial, w większości wzięty z dokumentacji biblioteki Audiere.
#include <audiere.h> using namespace audiere;
AudioDevicePtr device(OpenDevice());
if (!device)
{
// failture
}
Sama funkcja
OpenDevice ( const char* name = 0, const char* parameters = 0);pozwala na załadowanie konkretnego urządzenia w tym pustego null dostępnego (prawdopodobnie?) na każdej platformie.
OutputStreamPtr sound(
OpenSound(device, "music.wav", true));
if (!sound)
{
// failture
}
sound->play(); sound->stop(); sound->isPlaying(); // return bool sound->reset(); sound->setRepeat(bool repeat); // false | true sound->getRepeat(); sound->setVolume(float vol); // 0.0f - 1.0f sound->getVolume(); //setPan: -1.0 = left, 0.0 = center, 1.0 = right sound->setPan(float pan); sound->getPan(); // 0.5 - 2.0, 1.0 - default (100% speed) sound->setPitchShift(float shift); sound->getPitchShift(); sound->getLength(); // get number of frames sound->setPosition(0); // set current frame sound->getPosition();