1
Graphics / Unbinded Font Texture Problem
« on: April 12, 2010, 01:39:37 pm »
Ok, thanks soooo much! I really really appreciate it!
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
sf::RenderWindow win(sf::VideoMode(800, 600, 32), "Untitled!", sf::Style::Close, sf::ContextSettings(24, 8, 0, 1, 5));
win.Show(true);
win.SetActive();
Timer myTime;
Uint32 fps = 0;
Str typed = (Char)20140;
typed += (Char)20540;
typed += (Char)20940;
sf::Image img;
img.LoadFromFile(Str("Data/Raw/image.png").GetFilePath());
sf::Font font;
font.LoadFromFile(Str("Data/Raw/font2.ttc").GetFilePath());
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
sf::Text text;
while(1)
{
++fps;
if(myTime.IsOver())
{
SetWindowText(GetActiveWindow(), StrHelper.Put("Untitled! - %@1 fps", fps).ToWCString());
fps = 0;
myTime.SetTimer(1.0f);
}
sf::Event e;
while(win.GetEvent(e))
{
if(e.Type == sf::Event::Closed)
{
win.Close();
return;
}
if(e.Type == sf::Event::TextEntered)
{
if(e.Text.Unicode == '\b')
typed = typed.Substr(0, typed.GetSize()-1);
else
typed += (Char)e.Text.Unicode;
}
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glViewport(0, 0, 400, 300);
// glMatrixMode(GL_PROJECTION);
// glLoadIdentity();
// gluPerspective(45.f, 1.333f, 1.f, 500.f);
// glMatrixMode(GL_MODELVIEW);
// glLoadIdentity();
// glTranslatef(0.f, 0.f, -200.f);
// glRotatef(Time.GetElapsedTime() * 50, 1.f, 0.f, 0.f);
// glRotatef(Time.GetElapsedTime() * 30, 0.f, 1.f, 0.f);
// glRotatef(Time.GetElapsedTime() * 90, 0.f, 0.f, 1.f);
// img.Bind();
// glBegin(GL_QUADS);
// glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
// //glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
// glTexCoord2f(0, 0);
// glVertex3f(-50.f, -50.f, -50.f);
// glTexCoord2f(1, 0);
// glVertex3f(-50.f, 50.f, -50.f);
// glTexCoord2f(1, 1);
// glVertex3f( 50.f, 50.f, -50.f);
// glTexCoord2f(0, 1);
// glVertex3f( 50.f, -50.f, -50.f);
// //glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
// glTexCoord2f(0, 0);
// glVertex3f(-50.f, -50.f, 50.f);
// glTexCoord2f(1, 0);
// glVertex3f(-50.f, 50.f, 50.f);
// glTexCoord2f(1, 1);
// glVertex3f( 50.f, 50.f, 50.f);
// glTexCoord2f(0, 1);
// glVertex3f( 50.f, -50.f, 50.f);
// //glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
// glTexCoord2f(0, 0);
// glVertex3f(-50.f, -50.f, -50.f);
// glTexCoord2f(1, 0);
// glVertex3f(-50.f, 50.f, -50.f);
// glTexCoord2f(1, 1);
// glVertex3f(-50.f, 50.f, 50.f);
// glTexCoord2f(0, 1);
// glVertex3f(-50.f, -50.f, 50.f);
// //glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
// glTexCoord2f(0, 0);
// glVertex3f(50.f, -50.f, -50.f);
// glTexCoord2f(1, 0);
// glVertex3f(50.f, 50.f, -50.f);
// glTexCoord2f(1, 1);
// glVertex3f(50.f, 50.f, 50.f);
// glTexCoord2f(0, 1);
// glVertex3f(50.f, -50.f, 50.f);
// //glColor4f(1.0f, 0.0f, 1.0f, 1.0f);
// glTexCoord2f(0, 0);
// glVertex3f(-50.f, -50.f, 50.f);
// glTexCoord2f(1, 0);
// glVertex3f(-50.f, -50.f, -50.f);
// glTexCoord2f(1, 1);
// glVertex3f( 50.f, -50.f, -50.f);
// glTexCoord2f(0, 1);
// glVertex3f( 50.f, -50.f, 50.f);
// //glColor4f(0.0f, 1.0f, 1.0f, 1.0f);
// glTexCoord2f(0, 0);
// glVertex3f(-50.f, 50.f, 50.f);
// glTexCoord2f(1, 0);
// glVertex3f(-50.f, 50.f, -50.f);
// glTexCoord2f(1, 1);
// glVertex3f( 50.f, 50.f, -50.f);
// glTexCoord2f(0, 1);
// glVertex3f( 50.f, 50.f, 50.f);
// glEnd();
glViewport(400, 300, 400, 300);
glDisable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.f, 1.333f, 1.f, 500.f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.f, 0.f, -200.f);
glRotatef(Time.GetElapsedTime() * 50, 1.f, 0.f, 0.f);
glRotatef(Time.GetElapsedTime() * 30, 0.f, 1.f, 0.f);
glRotatef(Time.GetElapsedTime() * 90, 0.f, 0.f, 1.f);
glBegin(GL_QUADS);
glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
glVertex3f(-50.f, -50.f, -50.f);
glVertex3f(-50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f, -50.f);
glVertex3f( 50.f, -50.f, -50.f);
glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
glVertex3f(-50.f, -50.f, 50.f);
glVertex3f(-50.f, 50.f, 50.f);
glVertex3f( 50.f, 50.f, 50.f);
glVertex3f( 50.f, -50.f, 50.f);
glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
glVertex3f(-50.f, -50.f, -50.f);
glVertex3f(-50.f, 50.f, -50.f);
glVertex3f(-50.f, 50.f, 50.f);
glVertex3f(-50.f, -50.f, 50.f);
glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
glVertex3f(50.f, -50.f, -50.f);
glVertex3f(50.f, 50.f, -50.f);
glVertex3f(50.f, 50.f, 50.f);
glVertex3f(50.f, -50.f, 50.f);
glColor4f(1.0f, 0.0f, 1.0f, 1.0f);
glVertex3f(-50.f, -50.f, 50.f);
glVertex3f(-50.f, -50.f, -50.f);
glVertex3f( 50.f, -50.f, -50.f);
glVertex3f( 50.f, -50.f, 50.f);
glColor4f(0.0f, 1.0f, 1.0f, 1.0f);
glVertex3f(-50.f, 50.f, 50.f);
glVertex3f(-50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f, 50.f);
glEnd();
glEnable(GL_TEXTURE_2D);
glViewport(0, 0, 800, 600);
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, 800, 600, 0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
text.SetFont(font);
text.SetString(typed.ToWCString());
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
win.Draw(text);
glEnable(GL_DEPTH_TEST);
win.Display();
}
struct Sound
{
sf::Sound *sound;
sf::SoundBuffer *buffer;
ByteArray data;
};
Sound sound;
Sound *sd = &sound;
Malloc(sd->buffer, sf::SoundBuffer);
if(!sd->buffer->LoadFromFile(file.GetFilePath()))
{
Free(sd->buffer); // Free
WriteLog3("Missing audio file: %@1", file.TrimFilePath());
return;
}
Malloc(sd->sound, sf::Sound);
mSoundList.push_back(sound);
// Play sound
sd->sound->SetBuffer(*sd->buffer);
sd->sound->SetVolume(mSoundVol);
if(Math.DistanceSq(pos, mEye) < 1)
{
// 2D
sd->sound->SetRelativeToListener(true);
sd->sound->SetPosition(0, 0, 0);
}
else
{
// 3D
sd->sound->SetPosition(pos.x, pos.y, pos.z);
}
sd->sound->SetMinDistance(mDistance);
sd->sound->SetAttenuation(mAttenuation);
sd->sound->Play();