mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-07-07 07:00:33 -04:00
Added Graphics::DrawText which can draw text on to an image with alignment. No multi-line support yet.
This commit is contained in:
parent
7d9259b63d
commit
7a5124a687
8 changed files with 145 additions and 35 deletions
|
@ -15,6 +15,8 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <GL/gl.h>
|
||||
|
||||
#define EXIT_SCENE() do { System::SceneFailed = true; delete this; return; } while(0)
|
||||
#define SCENE_EXIT 0
|
||||
#define SCENE_NEED_REDRAW 1
|
||||
|
@ -22,11 +24,12 @@
|
|||
|
||||
class Scene {
|
||||
const float TickPeriod;
|
||||
float TimeDelta;
|
||||
float RealTimeDelta;
|
||||
virtual int Run(float TimeDelta) = 0;
|
||||
|
||||
protected:
|
||||
Scene(float c) : TickPeriod(c), TimeDelta(0) {}
|
||||
float TimeDelta;
|
||||
Scene(float c) : TickPeriod(c), RealTimeDelta(0) {}
|
||||
|
||||
public:
|
||||
int RunFor(float TimeDelta) {
|
||||
|
@ -35,54 +38,95 @@ class Scene {
|
|||
}
|
||||
|
||||
bool Redraw = false;
|
||||
this->TimeDelta += TimeDelta;
|
||||
while(this->TimeDelta >= 0){
|
||||
RealTimeDelta += TimeDelta;
|
||||
while(RealTimeDelta >= 0){
|
||||
int result = Run(TickPeriod);
|
||||
if(result == System::SHUTDOWN)
|
||||
return System::SHUTDOWN;
|
||||
if(result > 0) Redraw = true;
|
||||
this->TimeDelta -= TickPeriod;
|
||||
RealTimeDelta -= TickPeriod;
|
||||
}
|
||||
return (Redraw) ? 1 : -1;
|
||||
}
|
||||
|
||||
virtual void Render() = 0;
|
||||
virtual ~Scene() {};
|
||||
};
|
||||
|
||||
enum {
|
||||
TEX_EAGAMES,
|
||||
TEX_MAXIS,
|
||||
TEX_SETUP,
|
||||
TEX_COUNT
|
||||
};
|
||||
|
||||
static const char * const images[] = {"eagames.bmp", "maxis.png", "setup.bmp"};
|
||||
|
||||
class LoginScreen : public Scene {
|
||||
float Time;
|
||||
GLuint texture[TEX_COUNT];
|
||||
|
||||
public:
|
||||
LoginScreen() : Scene(1.0f/15){
|
||||
Image_t * Image = File::ReadImageFile("eagames.bmp");
|
||||
if(!Image){
|
||||
const char * Message;
|
||||
switch(File::Error){
|
||||
case FERR_NOT_FOUND:
|
||||
Message = "%s does not exist.";
|
||||
break;
|
||||
case FERR_OPEN:
|
||||
Message = "%s could not be opened for reading.";
|
||||
break;
|
||||
case FERR_BLANK:
|
||||
case FERR_UNRECOGNIZED:
|
||||
case FERR_INVALIDDATA:
|
||||
Message = "%s is corrupt or invalid.";
|
||||
break;
|
||||
case FERR_MEMORY:
|
||||
Message = "Memory for %s could not be allocated.";
|
||||
break;
|
||||
default:
|
||||
Message = "%s could not be read.";
|
||||
}
|
||||
Time = 0;
|
||||
|
||||
char Buffer[1024];
|
||||
sprintf(Buffer, Message, "eagames.bmp");
|
||||
MessageBox(Window::hWnd, Buffer, NULL, MB_OK | MB_ICONERROR);
|
||||
EXIT_SCENE();
|
||||
glMatrixMode(GL_TEXTURE);
|
||||
glGenTextures(TEX_COUNT, texture);
|
||||
|
||||
for(int i=0; i<TEX_COUNT; i++){
|
||||
Image_t * Image = File::ReadImageFile(images[i]);
|
||||
if(!Image){
|
||||
const char * Message;
|
||||
switch(File::Error){
|
||||
case FERR_NOT_FOUND:
|
||||
Message = "%s does not exist.";
|
||||
break;
|
||||
case FERR_OPEN:
|
||||
Message = "%s could not be opened for reading.";
|
||||
break;
|
||||
case FERR_BLANK:
|
||||
case FERR_UNRECOGNIZED:
|
||||
case FERR_INVALIDDATA:
|
||||
Message = "%s is corrupt or invalid.";
|
||||
break;
|
||||
case FERR_MEMORY:
|
||||
Message = "Memory for %s could not be allocated.";
|
||||
break;
|
||||
default:
|
||||
Message = "%s could not be read.";
|
||||
}
|
||||
|
||||
char Buffer[1024];
|
||||
sprintf(Buffer, Message, images[i]);
|
||||
MessageBox(Window::hWnd, Buffer, NULL, MB_OK | MB_ICONERROR);
|
||||
EXIT_SCENE();
|
||||
}
|
||||
|
||||
if(i == TEX_MAXIS){
|
||||
FT_Set_Char_Size(Graphics::FontFace, 0, 22*64, 0, 0);
|
||||
Graphics::DrawText(Image, L"Maxis\x2122 is an Electronic Arts\x2122 brand.", 0, 600-146, 800, 146,
|
||||
Graphics::ALIGN_CENTER_CENTER, 0, RGB(0xef, 0xe3, 0x8c));
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, texture[i]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, Image->Width, Image->Height, 0, GL_BGR, GL_UNSIGNED_BYTE, Image->Data);
|
||||
free(Image->Data);
|
||||
free(Image);
|
||||
}
|
||||
}
|
||||
|
||||
~LoginScreen(){
|
||||
glDeleteTextures(TEX_COUNT, texture);
|
||||
}
|
||||
|
||||
private:
|
||||
int Run(float){
|
||||
int Run(float TimeDelta){
|
||||
Time += TimeDelta;
|
||||
|
||||
if(System::UserInput.CloseWindow){
|
||||
return SCENE_EXIT;
|
||||
}
|
||||
|
@ -91,5 +135,13 @@ class LoginScreen : public Scene {
|
|||
|
||||
public:
|
||||
void Render(){
|
||||
glMatrixMode(GL_TEXTURE);
|
||||
glBindTexture(GL_TEXTURE_2D, texture[(Time>=4) + (Time>=8)]);
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2i(0,0); glVertex2i(0,0);
|
||||
glTexCoord2i(1,0); glVertex2i(800,0);
|
||||
glTexCoord2i(1,1); glVertex2i(800,600);
|
||||
glTexCoord2i(0,1); glVertex2i(0,600);
|
||||
glEnd();
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue