[4554] | 1 | /* |
---|
[4333] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
[6286] | 12 | main-programmer: David Hasenfratz |
---|
[4333] | 13 | co-programmer: ... |
---|
| 14 | |
---|
| 15 | this file extends the framework file, so it renders what i want. |
---|
| 16 | */ |
---|
| 17 | |
---|
| 18 | #include "framework.h" |
---|
| 19 | |
---|
[4343] | 20 | #include "light.h" |
---|
[4333] | 21 | |
---|
[5865] | 22 | #include "material.h" |
---|
[4343] | 23 | #include "primitive_model.h" |
---|
| 24 | #include <stdlib.h> |
---|
[4333] | 25 | |
---|
[6094] | 26 | #include "media_container.h" |
---|
[4343] | 27 | |
---|
| 28 | Model* obj; |
---|
[5866] | 29 | Material* testMat; |
---|
[6339] | 30 | MediaContainer* media_container; |
---|
[5866] | 31 | |
---|
[6168] | 32 | int counter = 0; |
---|
| 33 | float timer = 0; |
---|
| 34 | float fps; |
---|
[4343] | 35 | |
---|
[5866] | 36 | |
---|
[4343] | 37 | void Framework::moduleInit(int argc, char** argv) |
---|
[4333] | 38 | { |
---|
[6339] | 39 | if( argc <= 1) |
---|
[6168] | 40 | { |
---|
| 41 | printf("Wrong arguments try following notations:\n"); |
---|
[6339] | 42 | printf("./multitex [media_file]\n"); |
---|
[6168] | 43 | exit(0); |
---|
| 44 | } |
---|
[6094] | 45 | |
---|
[6339] | 46 | media_container = new MediaContainer(argv[1]); |
---|
[6163] | 47 | |
---|
[5866] | 48 | testMat = new Material; |
---|
[6163] | 49 | testMat->setDiffuseMap("maps/radialTransparency.png"); |
---|
[6003] | 50 | obj = new PrimitiveModel(PRIM_PLANE, 10.0); |
---|
[4333] | 51 | |
---|
[4343] | 52 | LightManager* lightMan = LightManager::getInstance(); |
---|
| 53 | lightMan->setAmbientColor(.1,.1,.1); |
---|
[4741] | 54 | (new Light())->setAbsCoor(5.0, 10.0, 40.0); |
---|
| 55 | (new Light())->setAbsCoor(-10, -20, -100); |
---|
[6339] | 56 | |
---|
| 57 | fps = media_container->getFPS(); |
---|
[4333] | 58 | } |
---|
| 59 | |
---|
[4334] | 60 | void Framework::moduleEventHandler(SDL_Event* event) |
---|
| 61 | { |
---|
| 62 | switch (event->type) |
---|
| 63 | { |
---|
| 64 | case SDL_KEYDOWN: |
---|
| 65 | switch (event->key.keysym.sym) |
---|
[4554] | 66 | { |
---|
[6003] | 67 | case SDLK_1: |
---|
[6013] | 68 | obj = new PrimitiveModel(PRIM_CUBE, 10.0); |
---|
[4554] | 69 | break; |
---|
[6068] | 70 | case SDLK_2: |
---|
[6013] | 71 | obj = new PrimitiveModel(PRIM_SPHERE, 10.0); |
---|
[6003] | 72 | break; |
---|
[6013] | 73 | case SDLK_3: |
---|
| 74 | obj = new PrimitiveModel(PRIM_PLANE, 10.0); |
---|
[6003] | 75 | break; |
---|
[6350] | 76 | case SDLK_5: |
---|
| 77 | media_container->loadFrames(); |
---|
| 78 | counter = 0; |
---|
| 79 | timer = 0; |
---|
| 80 | PRINTF(0)("total_frames: %i\n", media_container->getFrameCount()); |
---|
| 81 | SDL_Delay(1000); |
---|
| 82 | break; |
---|
[6168] | 83 | // increase fps |
---|
| 84 | case SDLK_9: |
---|
| 85 | fps++; |
---|
[6339] | 86 | PRINTF(0)("fps: %0.2f\n", fps); |
---|
[6168] | 87 | break; |
---|
| 88 | // decrease fps |
---|
| 89 | case SDLK_8: |
---|
| 90 | if(fps > 0) |
---|
| 91 | fps--; |
---|
[6339] | 92 | PRINTF(0)("fps: %0.2f\n", fps); |
---|
[6168] | 93 | break; |
---|
[4554] | 94 | } |
---|
[4334] | 95 | } |
---|
[4333] | 96 | } |
---|
| 97 | |
---|
| 98 | void Framework::moduleTick(float dt) |
---|
| 99 | { |
---|
[6168] | 100 | timer += dt; |
---|
[4554] | 101 | |
---|
[6168] | 102 | if(counter != fps * timer) |
---|
| 103 | { |
---|
| 104 | counter = fps * timer; |
---|
[6254] | 105 | |
---|
[6339] | 106 | if (counter >= media_container->getFrameCount()) |
---|
[6168] | 107 | { |
---|
| 108 | timer = 0; |
---|
| 109 | counter = 0; |
---|
[6350] | 110 | PRINTF(0)("BEGIN\n"); |
---|
[6168] | 111 | } |
---|
[6254] | 112 | } |
---|
[4333] | 113 | } |
---|
| 114 | |
---|
[4349] | 115 | void Framework::moduleDraw(void) const |
---|
[4334] | 116 | { |
---|
[5866] | 117 | testMat->select(); |
---|
[6339] | 118 | glBindTexture(GL_TEXTURE_2D, media_container->getFrameTexture(counter)); |
---|
[4343] | 119 | obj->draw(); |
---|
| 120 | |
---|
| 121 | LightManager::getInstance()->draw(); |
---|
[4334] | 122 | } |
---|
[4333] | 123 | |
---|
| 124 | void Framework::moduleHelp(void) const |
---|
| 125 | { |
---|
[4554] | 126 | |
---|
[4333] | 127 | } |
---|