TORCS  1.3.10
The Open Racing Car Simulator
Loading...
Searching...
No Matches
splash.cpp
Go to the documentation of this file.
1/***************************************************************************
2
3 file : splash.cpp
4 created : Sat Mar 18 23:49:03 CET 2000
5 copyright : (C) 2000 by Eric Espie
6 email : torcs@free.fr
7 version : $Id$
8
9 ***************************************************************************/
10
11/***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19#ifdef WIN32
20#include <windows.h>
21#define HAVE_CONFIG_H
22#endif
23#include <GL/glut.h>
24#include <stdlib.h>
25#include <stdio.h>
26#include <portability.h>
27
28#ifdef HAVE_CONFIG_H
29#include "config.h"
30#endif
31
32#include <tgfclient.h>
33
34#include "splash.h"
35#include "mainmenu.h"
36
38static GLuint s_texture = 0;
40
41/*
42 * Function
43 * splashKey
44 *
45 * Description
46 *
47 *
48 * Parameters
49 *
50 *
51 * Return
52 *
53 *
54 * Remarks
55 *
56 */
57static void splashKey( unsigned char /* key */, int /* x */, int /* y */)
58{
60 glDeleteTextures(1, &s_texture);
61 s_texture = 0;
63}
64
65/*
66 * Function
67 *
68 *
69 * Description
70 *
71 *
72 * Parameters
73 *
74 *
75 * Return
76 *
77 *
78 * Remarks
79 *
80 */
81static void splashTimer(int /* value */)
82{
83 if (SplashDisplaying) {
85 glDeleteTextures(1, &s_texture);
86 s_texture = 0;
88 }
89}
90
91
92/*
93 * Function
94 * splashDisplay
95 *
96 * Description
97 *
98 *
99 * Parameters
100 *
101 *
102 * Return
103 *
104 *
105 * Remarks
106 *
107 */
108static void splashDisplay( void )
109{
110 int ScrW, ScrH, ViewW, ViewH;
111
113
114 glDisable(GL_DEPTH_TEST);
115 glDisable(GL_LIGHTING);
116 glDisable(GL_CULL_FACE);
117 glDisable(GL_ALPHA_TEST);
118
120
121 glViewport((ScrW-ViewW) / 2, (ScrH-ViewH) / 2, ViewW, ViewH);
122 glMatrixMode(GL_PROJECTION);
123 glLoadIdentity();
124 gluOrtho2D(0, ScrW, 0, ScrH);
125 glMatrixMode(GL_MODELVIEW);
126 glLoadIdentity();
127
128 if (s_texture != 0) {
129 GLfloat tx1 = 0.0f, tx2 = 1.0f, ty1 = 0.0f, ty2 = 1.0f;
130
131 // Compute texture coordinates to ensure proper unskewed/unstretched display of
132 // image content.
133 //tdble rfactor = (float)(s_imgWidth*ViewH)/(float)(s_imgHeight*ViewW);
134 tdble rfactor = (16.0f*ViewH)/(10.0f*ViewW);
135
136 if (rfactor >= 1.0f) {
137 // Aspect ratio of view is smaller than 16:10, "cut off" sides
138 tdble tdx = (1.0f-1.0f/rfactor)/2.0f;
139 tx1 += tdx;
140 tx2 -= tdx;
141 } else {
142 // Aspect ratio of view is larger than 16:10, "cut off" top and bottom
143 tdble tdy = (1.0f-rfactor)/2.0f;
144 ty1 += tdy;
145 ty2 -= tdy;
146 }
147
148 glEnable(GL_TEXTURE_2D);
149 glBindTexture(GL_TEXTURE_2D, s_texture);
150 glBegin(GL_QUADS);
151 glTexCoord2f(tx1, ty1); glVertex3f(0.0, 0.0, 0.0);
152 glTexCoord2f(tx1, ty2); glVertex3f(0.0, ScrH, 0.0);
153 glTexCoord2f(tx2, ty2); glVertex3f(ScrW, ScrH, 0.0);
154 glTexCoord2f(tx2, ty1); glVertex3f(ScrW, 0.0, 0.0);
155 glEnd();
156 glDisable(GL_TEXTURE_2D);
157 }
158
159#ifdef HAVE_CONFIG_H
160 glMatrixMode(GL_PROJECTION);
161 glLoadIdentity();
162 gluOrtho2D(0, 640, 0, 480);
163
164 static float grWhite[4] = {1.0, 1.0, 1.0, 1.0};
166#endif
167
168 glutSwapBuffers();
169}
170
171static void splashMouse(int /* b */, int s, int /* x */, int /* y */)
172{
173 if (s == GLUT_UP) {
175 glDeleteTextures(1, &s_texture);
176 s_texture = 0;
178 }
179}
180
181
182/*
183 * Function
184 *
185 *
186 * Description
187 *
188 *
189 * Parameters
190 *
191 *
192 * Return
193 *
194 *
195 * Remarks
196 *
197 */
199{
200 void *handle;
201 float screen_gamma;
202 const char *filename = "data/img/splash.png";
203 const int BUFSIZE = 1024;
204 char buf[BUFSIZE];
205
206 if (s_texture != 0) {
207 glDeleteTextures(1, &s_texture);
208 }
209
210 snprintf(buf, BUFSIZE, "%s%s", GetLocalDir(), GFSCR_CONF_FILE);
212 screen_gamma = (float)GfParmGetNum(handle, GFSCR_SECT_PROP, GFSCR_ATT_GAMMA, (char*)NULL, 2.0);
213 GLbyte *tex = (GLbyte*)GfImgReadPng(filename, &s_imgWidth, &s_imgHeight, screen_gamma);
214 GfParmReleaseHandle(handle);
215 if (!tex) {
216 GfTrace("Couldn't read %s\n", filename);
217 return -1;
218 }
219
220 glGenTextures(1, &s_texture);
221 glBindTexture(GL_TEXTURE_2D, s_texture);
222 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
223 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
224 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, s_imgWidth, s_imgHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *)(tex));
225 free(tex);
226
227 glutDisplayFunc(splashDisplay);
228 glutKeyboardFunc(splashKey);
229 glutSpecialFunc((void (*)(int key, int x, int y))NULL);
230 glutTimerFunc(7000, splashTimer, 0);
231 glutMouseFunc(splashMouse);
232
233 return 0;
234}
235
236
static Vector y[4]
Definition Convex.cpp:56
static float grWhite[4]
Definition grboard.cpp:40
float tdble
Floating point type used in TORCS.
Definition tgf.h:47
void GfuiPrintString(const char *text, float *fgColor, int font, int x, int y, int align)
Draw text immediately in the current OpenGL context without creating a widget.
Definition guiobject.cpp:43
unsigned char * GfImgReadPng(const char *filename, int *widthp, int *heightp, float screen_gamma)
Load an image from disk to a buffer in RGBA mode.
Definition img.cpp:53
tdble GfParmGetNum(void *handle, const char *path, const char *key, const char *unit, tdble deflt)
Get a numerical parameter from the parameter set handle.
Definition params.cpp:2534
void GfParmReleaseHandle(void *parmHandle)
Release given parameter set handle parmHandle.
Definition params.cpp:1963
void * GfParmReadFile(const char *file, int mode)
Read parameter set from file and return handle to parameter set.
Definition params.cpp:1173
void GfScrGetSize(int *scrw, int *scrh, int *vieww, int *viewh)
Get the screen and viewport sizes.
Definition screen.cpp:529
static int ScrH
Definition gui.cpp:40
static int ViewW
Definition gui.cpp:40
static int ScrW
Definition gui.cpp:40
static int ViewH
Definition gui.cpp:40
int TorcsMainMenuRun(void)
Definition mainmenu.cpp:118
#define GFSCR_CONF_FILE
#define GFSCR_SECT_PROP
#define GFSCR_ATT_GAMMA
static GLuint s_texture
Definition splash.cpp:38
static void splashKey(unsigned char, int, int)
Definition splash.cpp:57
static void splashTimer(int)
Definition splash.cpp:81
static void splashDisplay(void)
Definition splash.cpp:108
static int s_imgHeight
Definition splash.cpp:37
int SplashScreen(void)
Definition splash.cpp:198
static void splashMouse(int, int s, int, int)
Definition splash.cpp:171
static int SplashDisplaying
Definition splash.cpp:39
static int s_imgWidth
Definition splash.cpp:37
char * GetLocalDir(void)
Definition tgf.cpp:230
#define GFPARM_RMODE_CREAT
Allow an empty in-memory set on file-open failure; does not write a file.
Definition tgf.h:266
#define GFPARM_RMODE_STD
Return a new handle sharing cached data for this filename, if available.
Definition tgf.h:264
#define GfTrace
Definition tgf.h:335
#define GFUI_FONT_SMALL_C
Definition tgfclient.h:254
#define GFUI_ALIGN_HR_VB
Definition tgfclient.h:77