~ubuntu-branches/ubuntu/quantal/zaz/quantal

« back to all changes in this revision

Viewing changes to src/gameloop.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Miriam Ruiz
  • Date: 2009-08-31 20:08:58 UTC
  • Revision ID: james.westby@ubuntu.com-20090831200858-54lcmcrna6dwk3wr
Tags: upstream-0.2.9+dfsg1
ImportĀ upstreamĀ versionĀ 0.2.9+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Zaz
 
3
 * Copyright (C) Remigiusz Dybka 2009 <remigiusz.dybka@gmail.com>
 
4
 *
 
5
 Zaz is free software: you can redistribute it and/or modify it
 
6
 under the terms of the GNU General Public License as published by the
 
7
 Free Software Foundation, either version 3 of the License, or
 
8
 (at your option) any later version.
 
9
 
 
10
 Zaz is distributed in the hope that it will be useful, but
 
11
 WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
13
 See the GNU General Public License for more details.
 
14
 
 
15
 You should have received a copy of the GNU General Public License along
 
16
 with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
#include "gameloop.h"
 
20
#include "level.h"
 
21
#include "textureloader.h"
 
22
#include "lineeditor.h"
 
23
#ifdef WIN32
 
24
#include <shlobj.h>
 
25
#include <shlwapi.h>
 
26
#endif
 
27
#include <sstream>
 
28
#include <ctime>
 
29
 
 
30
GameLoop::GameLoop(Scenes::Settings *settings, SDL_Surface *surf, GLuint *gameTextures, uint startLevel, uint randomSeed)
 
31
        : Scene(settings, surf), score(0), lastscore(0), currentLevelName(startLevel), randomSeed((uint)time(0)), gameTextures(gameTextures),
 
32
        showMenu(false), gameOver(false), showPauseMenu(false), continueGame(false), showLifeLostMenu(false), pwned(false), hiScore(false), game(0),
 
33
        logoTexture(LoadTexture ("logo.png")),screenShotTexture(0), pwnedr(0), editor(settings->get("lastHighscoreName", ""), 60, 50, 16),
 
34
        livesLeft(nLives), livesLeftInReplay(nLives)
 
35
{
 
36
    // create level list
 
37
    bool found = true;
 
38
    int f = 1;
 
39
 
 
40
    while (found)
 
41
    {
 
42
        std::stringstream ss;
 
43
        ss << "level" << f << ".lvl";
 
44
 
 
45
        std::ifstream inph(settings->getCFilename(ss.str()));
 
46
        if (inph)
 
47
        {
 
48
            levelNames.push_back(settings->getCFilename(ss.str()));
 
49
            ++f;
 
50
        }
 
51
        else
 
52
        {
 
53
            found = false;
 
54
        }
 
55
    };
 
56
 
 
57
    pauseMenu.Add(new GenericMenuItem(_("End game"), pauseMenuEndGameHandler, this));
 
58
    pauseMenu.Add(new GenericMenuItem(_("Continue"), pauseMenuContinueHandler, this));
 
59
 
 
60
    pauseMenu.SetDimensions(30, 40, 40);
 
61
 
 
62
    nextLevelMenu.Add(new GenericMenuItem(_("Next level"), nextLevelMenuNextLevelHandler, this));
 
63
    nextLevelMenu.Add(new GenericMenuItem(_("End game"), pauseMenuEndGameHandler, this));
 
64
    nextLevelMenu.Add(new GenericMenuItem(_("View replay"), nextLevelMenuViewReplayHandler, this));
 
65
    nextLevelMenu.Add(new GenericMenuItem(_("Export video"), nextLevelMenuExportVideoHandler, this));
 
66
 
 
67
    nextLevelMenu.SetDimensions(30, 40, 40);
 
68
 
 
69
    gameOverMenu.Add(new GenericMenuItem(_("Back to main menu"), pauseMenuEndGameHandler, this));
 
70
    gameOverMenu.Add(new GenericMenuItem(_("Restart game"), gameOverMenuRestartHandler, this));
 
71
    gameOverMenu.Add(new GenericMenuItem(_("View replay"), nextLevelMenuViewReplayHandler, this));
 
72
    gameOverMenu.Add(new GenericMenuItem(_("Export video"), nextLevelMenuExportVideoHandler, this));
 
73
 
 
74
    gameOverMenu.SetDimensions(30, 40, 40);
 
75
 
 
76
    lifeLostMenu.Add(new GenericMenuItem(_("Retry level"), lifeLostMenuRetryLevelHandler, this));
 
77
    lifeLostMenu.Add(new GenericMenuItem(_("End game"), pauseMenuEndGameHandler, this));
 
78
    lifeLostMenu.Add(new GenericMenuItem(_("View replay"), nextLevelMenuViewReplayHandler, this));
 
79
    lifeLostMenu.Add(new GenericMenuItem(_("Export video"), nextLevelMenuExportVideoHandler, this));
 
80
 
 
81
    lifeLostMenu.SetDimensions(30, 40, 40);
 
82
 
 
83
    pwned = false;
 
84
 
 
85
#ifdef WIN32
 
86
    tempRecording << " "; // braindead !!!
 
87
#endif
 
88
}
 
89
 
 
90
void GameLoop::ClearGame()
 
91
{
 
92
    if (game)
 
93
    {
 
94
        delete game;
 
95
        delete level;
 
96
 
 
97
        game = 0;
 
98
    }
 
99
}
 
100
 
 
101
void gameOverMenuRestartHandler(void *ptr)
 
102
{
 
103
    GameLoop *p = (GameLoop*)ptr;
 
104
    p->score = 0;
 
105
    p->currentLevelName = 0;
 
106
    p->gameOver = false;
 
107
};
 
108
 
 
109
void GameLoop::ViewReplay()
 
110
{
 
111
    stringstream rec;
 
112
    rec << recording;
 
113
 
 
114
    ClearGame();
 
115
    level = new Level(levelNames[currentLevelName].c_str());
 
116
    game = new Game(settings, surface, *level, gameTextures, randomSeed, livesLeftInReplay, lastscore);
 
117
    game->Play(rec);
 
118
    ClearGame();
 
119
}
 
120
 
 
121
void lifeLostMenuRetryLevelHandler(void *ptr)
 
122
{
 
123
    GameLoop *p = (GameLoop*)ptr;
 
124
    p->showLifeLostMenu = false;
 
125
}
 
126
 
 
127
void GameLoop::NextLevel()
 
128
{
 
129
    currentLevelName++;
 
130
    showMenu = false;
 
131
}
 
132
 
 
133
void nextLevelMenuNextLevelHandler(void *ptr)
 
134
{
 
135
    GameLoop *p = (GameLoop*)ptr;
 
136
    p->NextLevel();
 
137
}
 
138
 
 
139
void nextLevelMenuViewReplayHandler(void *ptr)
 
140
{
 
141
    GameLoop *p = (GameLoop*)ptr;
 
142
    p->ViewReplay();
 
143
}
 
144
 
 
145
void GameLoop::ExportReplay()
 
146
{
 
147
    ClearGame();
 
148
 
 
149
    level = new Level(levelNames[currentLevelName].c_str());
 
150
    stringstream rec;
 
151
    rec << recording;
 
152
    game = new Game(settings, surface, *level, gameTextures, randomSeed, livesLeftInReplay, lastscore);
 
153
 
 
154
    time_t theTime;
 
155
    time( &theTime );
 
156
    tm *t = localtime( &theTime );
 
157
    char tempbuff[256];
 
158
    char datebuff[256];
 
159
 
 
160
    string exportpath = ".";
 
161
 
 
162
#ifdef WIN32
 
163
    TCHAR path[MAX_PATH];
 
164
    if (SUCCEEDED(SHGetFolderPath(NULL,
 
165
                                  CSIDL_PERSONAL,
 
166
                                  NULL,
 
167
                                  0,
 
168
                                  path)))
 
169
    {
 
170
        exportpath = path;
 
171
    }
 
172
#endif
 
173
 
 
174
    sprintf(datebuff, "%04d-%02d-%02d", 1900 + t->tm_year, t->tm_mon + 1, t->tm_mday);
 
175
 
 
176
    sprintf(tempbuff, "%s%szaz-%s.ogv", exportpath.c_str(), SEPARATOR, datebuff);
 
177
    bool ok = false;
 
178
    int f = 1;
 
179
    while (!ok)
 
180
    {
 
181
        ifstream inph(tempbuff);
 
182
        if (!inph)
 
183
        {
 
184
            ok = true;
 
185
        }
 
186
        else
 
187
        {
 
188
            sprintf(tempbuff, "%s%szaz-%s-%d.ogv", exportpath.c_str(), SEPARATOR, datebuff, f);
 
189
            ++f;
 
190
        }
 
191
    }
 
192
 
 
193
    string exportphname = tempbuff;
 
194
 
 
195
    game->Export(exportphname, rec, 4);
 
196
    ClearGame();
 
197
}
 
198
 
 
199
void nextLevelMenuExportVideoHandler(void *ptr)
 
200
{
 
201
    GameLoop *p = (GameLoop*)ptr;
 
202
    p->ExportReplay();
 
203
}
 
204
 
 
205
void pauseMenuContinueHandler(void *ptr)
 
206
{
 
207
    GameLoop *p = (GameLoop*)ptr;
 
208
    p->continueGame = true;
 
209
    p->showPauseMenu = false;
 
210
};
 
211
 
 
212
void pauseMenuEndGameHandler(void *ptr)
 
213
{
 
214
    GameLoop *p = (GameLoop*)ptr;
 
215
    p->quit = true;
 
216
};
 
217
 
 
218
 
 
219
GameLoop::~GameLoop()
 
220
{
 
221
    if (screenShotTexture)
 
222
        glDeleteTextures(1, &screenShotTexture);
 
223
 
 
224
    glDeleteTextures(1, &logoTexture);
 
225
 
 
226
}
 
227
 
 
228
void GameLoop::GLSetup()
 
229
{
 
230
    SDL_ShowCursor(SDL_ENABLE);
 
231
    SDL_WM_GrabInput(SDL_GRAB_OFF);
 
232
 
 
233
    int width = surface->w;
 
234
    int height = surface->h;
 
235
 
 
236
    //    float ratio = (float) width / (float) height;
 
237
 
 
238
    /* Our shading model--Gouraud (smooth). */
 
239
    glShadeModel( GL_SMOOTH );
 
240
 
 
241
    /* Culling. */
 
242
    glCullFace( GL_BACK );
 
243
    glFrontFace( GL_CCW );
 
244
    glEnable( GL_CULL_FACE );
 
245
    glEnable(GL_DEPTH_TEST);
 
246
    glEnable( GL_ALPHA_TEST );
 
247
    glAlphaFunc(GL_GREATER, 0.0);
 
248
    glEnable(GL_LINE_SMOOTH);
 
249
 
 
250
    glEnable(GL_BLEND);
 
251
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
252
 
 
253
    glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
 
254
    glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
 
255
    glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
 
256
 
 
257
    glClearColor( .1f, .1f, .7f, 1.0f );
 
258
    glViewport( 0, 0, width, height);
 
259
    glMatrixMode( GL_PROJECTION );
 
260
    glLoadIdentity( );
 
261
 
 
262
    vwidth = 100 * (640.0/480.0);
 
263
    vleft = (100 - vwidth) / 2;
 
264
    vheight = 100.0;
 
265
 
 
266
    glOrtho(vleft, vwidth + vleft, 0, 100, -100, 100);
 
267
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
 
268
}
 
269
 
 
270
void GameLoop::Logic(ulong frame)
 
271
{
 
272
    if (!events.empty)
 
273
    {
 
274
        if (events.keyDown.size() > 0)
 
275
            for (vector<SDLKey>::iterator i = events.keyDown.begin(); i != events.keyDown.end(); ++i)
 
276
            {
 
277
                if (*i == SDLK_ESCAPE)
 
278
                {
 
279
                    if (!showPauseMenu && !hiScore)
 
280
                    {
 
281
                        quit = true;
 
282
                    }
 
283
                    else if (showPauseMenu)
 
284
                    {
 
285
                        continueGame = true;
 
286
                        showPauseMenu = false;
 
287
                    }
 
288
 
 
289
                    if (hiScore)
 
290
                    {
 
291
                        hiScore = false;
 
292
                    }
 
293
                }
 
294
 
 
295
                if (hiScore)
 
296
                    if (*i == SDLK_RETURN || *i == SDLK_KP_ENTER)
 
297
                    {
 
298
                        hiScores.SubmitHiScore(HiScoreEntry(score, editor.txt, level->name));
 
299
                        settings->set("lastHighscoreName", editor.txt);
 
300
                        hiScore = false;
 
301
                                                SDL_EnableUNICODE(SDL_DISABLE);
 
302
                    }
 
303
            }
 
304
 
 
305
        double mx = (vwidth * events.mouseX) + vleft;
 
306
        double my = vheight - (vheight * events.mouseY);
 
307
        bool click = false;
 
308
 
 
309
        if (events.buttDown[0])
 
310
            click = true;
 
311
 
 
312
        if (showLifeLostMenu)
 
313
            lifeLostMenu.Logic(mx, my, click);
 
314
 
 
315
        if (showPauseMenu)
 
316
            pauseMenu.Logic(mx, my, click);
 
317
 
 
318
        if (showMenu)
 
319
            nextLevelMenu.Logic(mx, my, click);
 
320
 
 
321
        if (gameOver)
 
322
            gameOverMenu.Logic(mx, my, click);
 
323
    }
 
324
 
 
325
    if (quit)
 
326
    {
 
327
        ClearGame();
 
328
        return;
 
329
    }
 
330
 
 
331
    if (hiScore)
 
332
    {
 
333
        editor.Logic(events);
 
334
    }
 
335
 
 
336
    if (!showLifeLostMenu && !showMenu && !gameOver && !showPauseMenu && !hiScore)
 
337
    {
 
338
        if (!continueGame)
 
339
        {
 
340
            ClearGame();
 
341
            level = new Level(levelNames[currentLevelName].c_str());
 
342
            randomSeed = (uint)time(0);
 
343
            tempRecording.clear();
 
344
            tempRecording.seekp(0);
 
345
            game = new Game(settings, surface, *level, gameTextures, randomSeed, livesLeft, score);
 
346
        }
 
347
 
 
348
        if (continueGame)
 
349
        {
 
350
            game->quit = false;
 
351
            game->escaped = false;
 
352
            game->Record(tempRecording, pausedFrame);
 
353
            continueGame = false;
 
354
            GenScreenShotTexture();
 
355
            GLSetup();
 
356
        }
 
357
        else
 
358
        {
 
359
            livesLeftInReplay = livesLeft;
 
360
            game->Record(tempRecording, 0);
 
361
            GenScreenShotTexture();
 
362
            GLSetup();
 
363
        }
 
364
 
 
365
        if (game->escaped)
 
366
        {
 
367
            showPauseMenu = true;
 
368
            pausedFrame = game->getLastLogicFrame();
 
369
        }
 
370
        else
 
371
        {
 
372
            if (!game->gameOver)
 
373
            { // finished level
 
374
                lastscore = score;
 
375
                score=game->score;
 
376
                livesLeft = game->lives;
 
377
 
 
378
                stringstream cfgs;
 
379
                cfgs << "level" << (currentLevelName + 1) << "_completed";
 
380
 
 
381
                settings->setb(cfgs.str(), true);
 
382
 
 
383
                if (currentLevelName < levelNames.size() - 1)
 
384
                {
 
385
                    showMenu = true;
 
386
                }
 
387
                else   // pwned the game !!!
 
388
                {
 
389
                    gameOver = true;
 
390
                    pwned = true;
 
391
                    if (hiScores.GoodEnough (score))
 
392
                                        {
 
393
                        hiScore = true;
 
394
                                                SDL_EnableUNICODE(SDL_ENABLE);
 
395
                                        }
 
396
                }
 
397
                GenScreenShotTexture();
 
398
                GLSetup();
 
399
                recording = tempRecording.str();
 
400
            }
 
401
            else
 
402
            { // lost a life
 
403
                lastscore = score;
 
404
                score=game->score;
 
405
                livesLeft = (int)game->lives;
 
406
                livesLeft--;
 
407
 
 
408
                if (livesLeft >= 0)
 
409
                {
 
410
                    showLifeLostMenu = true;
 
411
                    recording = tempRecording.str();
 
412
                    return;
 
413
                };
 
414
 
 
415
                gameOver = true;
 
416
                if (hiScores.GoodEnough (score))
 
417
                                {
 
418
                                        SDL_EnableUNICODE(SDL_ENABLE);
 
419
                                        hiScore = true;
 
420
                                }
 
421
 
 
422
                livesLeft = nLives;
 
423
                recording = tempRecording.str();
 
424
            }
 
425
        }
 
426
    }
 
427
 
 
428
    if (pwned)
 
429
        pwnedr+=0.01;
 
430
}
 
431
 
 
432
void GameLoop::CenterMsg(string msg, double y, FTFont *font)
 
433
{
 
434
    glLoadIdentity( );
 
435
    FTBBox b = font->BBox(msg.c_str());
 
436
    double tw = b.Upper().X() / 5;
 
437
    glTranslated((100 - tw) / 2, y, 5);
 
438
    glScaled(0.2, 0.2, 0.2);
 
439
 
 
440
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 
441
    font->Render(msg.c_str());
 
442
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
 
443
}
 
444
 
 
445
 
 
446
void GameLoop::Render(ulong frame)
 
447
{
 
448
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
449
    glColor3f(1.0, 1.0, 1.0);
 
450
    glMatrixMode( GL_MODELVIEW );
 
451
    glLoadIdentity( );
 
452
 
 
453
    if (screenShotTexture != 0)
 
454
    {
 
455
        // render level background
 
456
        glPushMatrix();
 
457
        glTranslatef(0.0, 0.0, -5);
 
458
        glEnable(GL_TEXTURE_2D);
 
459
        glBindTexture(GL_TEXTURE_2D, screenShotTexture);
 
460
        glBegin(GL_QUADS);
 
461
        glTexCoord2d(0, 0);
 
462
        glVertex3d(vleft, 100, 0);
 
463
        glTexCoord2d(0, 1);
 
464
        glVertex3d(vleft, 0, 0);
 
465
        glTexCoord2d(1, 1);
 
466
        glVertex3d(vleft + vwidth, 0, 0);
 
467
        glTexCoord2d(1, 0);
 
468
        glVertex3d(vleft + vwidth, 100, 0);
 
469
        glEnd();
 
470
        glDisable(GL_TEXTURE_2D);
 
471
        glPopMatrix();
 
472
    }
 
473
 
 
474
    if (showLifeLostMenu)
 
475
    {
 
476
        lifeLostMenu.Render();
 
477
        glLoadIdentity( );
 
478
        glColor3d(1.0, 1.0, 1.0);
 
479
 
 
480
        char msgscore[256];
 
481
        sprintf(msgscore, _("Lives left: %d"), livesLeft);
 
482
        CenterMsg(msgscore, 50, font);
 
483
 
 
484
        sprintf(msgscore, _("Current score: %05d"), score);
 
485
 
 
486
        CenterMsg(msgscore, 45, font);
 
487
    }
 
488
 
 
489
    if (showPauseMenu)
 
490
    {
 
491
        pauseMenu.Render();
 
492
        string msg = _("Game paused");
 
493
        glColor3d(1.0, 0.0, 0.0);
 
494
 
 
495
        CenterMsg(msg, 45, font);
 
496
    }
 
497
 
 
498
    if (showMenu)
 
499
    {
 
500
        nextLevelMenu.Render();
 
501
 
 
502
        glLoadIdentity( );
 
503
 
 
504
        glColor3d(1.0, 1.0, 1.0);
 
505
        CenterMsg(_("Level cleared"), 50, font);
 
506
 
 
507
        char msgscore[256];
 
508
        sprintf(msgscore, _("Current score: %05d"), score);
 
509
 
 
510
        CenterMsg(msgscore, 45, font);
 
511
    }
 
512
 
 
513
 
 
514
    if (gameOver && !hiScore)
 
515
    {
 
516
        gameOverMenu.Render();
 
517
 
 
518
        glLoadIdentity( );
 
519
        string msg = _("Game Over");
 
520
 
 
521
        glColor3d(1.0, 0.0, 0.0);
 
522
 
 
523
        CenterMsg(msg, 50, font);
 
524
        char msgscore[256];
 
525
        sprintf(msgscore, _("Score: %05d"), score);
 
526
        glColor3d(1.0, 1.0, 1.0);
 
527
        CenterMsg(msgscore, 45, font);
 
528
    }
 
529
 
 
530
    if (pwned && !hiScore)
 
531
    {
 
532
        glColor3d(1.0, 1.0, 1.0);
 
533
        CenterMsg(_("Congratulations !!! You just pwned"), 90, font3);
 
534
 
 
535
        // logo
 
536
        glLoadIdentity();
 
537
        glPopMatrix();
 
538
        glEnable(GL_TEXTURE_2D);
 
539
        glTranslated(15 + 30 * cos(pwnedr), 90, 5);
 
540
        glBindTexture(GL_TEXTURE_2D, logoTexture);
 
541
        glScalef(70, 41, 5);
 
542
        glBegin(GL_QUADS);
 
543
        glTexCoord2d(0, 0);
 
544
        glVertex3d(0, 0, 0);
 
545
        glTexCoord2d(0, 1);
 
546
        glVertex3d(0, -1, 0);
 
547
        glTexCoord2d(1, 1);
 
548
        glVertex3d(1, -1, 0);
 
549
        glTexCoord2d(1, 0);
 
550
        glVertex3d(1, 0, 0);
 
551
        glEnd();
 
552
        glDisable(GL_TEXTURE_2D);
 
553
    }
 
554
 
 
555
    if (hiScore)
 
556
    {
 
557
        glColor3d(1.0, 1.0, 1.0);
 
558
        CenterMsg(_("You have a new hi score"), 65, font);
 
559
        CenterMsg(_("please enter your name"), 60, font);
 
560
        editor.Render();
 
561
    }
 
562
}
 
563
 
 
564
void GameLoop::GenScreenShotTexture()
 
565
{
 
566
    if (screenShotTexture)
 
567
    {
 
568
        glDeleteTextures(1, &screenShotTexture);
 
569
    }
 
570
 
 
571
    unsigned char *pixels;
 
572
    unsigned char *temp;
 
573
 
 
574
    glFlush();
 
575
 
 
576
    pixels = (unsigned char *)malloc(3 * surface->w * surface->h);
 
577
    temp = (unsigned char *)malloc(3 * screenShotTextureSize * screenShotTextureSize);
 
578
 
 
579
    glReadPixels(0, 0, surface->w, surface->h,
 
580
                 GL_RGB, GL_UNSIGNED_BYTE, pixels);
 
581
 
 
582
    double sx = (double)surface->w / (double)screenShotTextureSize;
 
583
    double sy = (double)surface->h / (double)screenShotTextureSize;
 
584
 
 
585
    for (uint y = 0; y < screenShotTextureSize; ++y)
 
586
        for (uint x = 0; x < screenShotTextureSize; ++x)
 
587
        {
 
588
            uint yy = (uint)iround(double(y) * sy);
 
589
            uint xx = (uint)iround(double(x) * sx);
 
590
            unsigned char *p = pixels + (((surface->h - 1) - yy) * 3 * surface->w) + (xx * 3);
 
591
            unsigned char *pt = temp + (y * 3 * screenShotTextureSize) + (x * 3);
 
592
 
 
593
            unsigned char r = p[0];
 
594
            unsigned char g = p[1];
 
595
            unsigned char b = p[2];
 
596
 
 
597
            int newcol = (((int)r + (int)g + (int)b) / 3) - 10;
 
598
            if (newcol < 0)
 
599
                newcol = 0;
 
600
 
 
601
            unsigned char nc = (unsigned char)newcol;
 
602
 
 
603
            pt[0] = 0;
 
604
            pt[1] = 0;
 
605
            pt[2] = nc;
 
606
        };
 
607
 
 
608
    glGenTextures( 1, &screenShotTexture);
 
609
 
 
610
    glBindTexture( GL_TEXTURE_2D, screenShotTexture);
 
611
 
 
612
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
 
613
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
 
614
 
 
615
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
 
616
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
 
617
 
 
618
    glTexImage2D( GL_TEXTURE_2D, 0, 3, screenShotTextureSize, screenShotTextureSize, 0,
 
619
                  GL_RGB, GL_UNSIGNED_BYTE, temp);
 
620
 
 
621
    free(pixels);
 
622
    free(temp);
 
623
}
 
624