engine.h
上传用户:qccn516
上传日期:2013-05-02
资源大小:3382k
文件大小:5k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. /* 3D Engine
  2.  *
  3.  * Copyright (C) 2003-2004, Alexander Zaprjagaev <frustum@frustum.org>
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or
  8.  * (at your option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18.  */
  19. #ifndef __ENGINE_H__
  20. #define __ENGINE_H__
  21. #ifdef _WIN32
  22. #include <windows.h>
  23. #include <io.h>
  24. #include <fcntl.h>
  25. #pragma warning(disable: 4244)
  26. #pragma warning(disable: 4305)
  27. #else
  28. #include <unistd.h>
  29. #include <fcntl.h>
  30. #endif
  31. #include <GL/gl.h>
  32. #include <GL/glext.h>
  33. #ifdef _WIN32
  34. #include "win32/glext.h"
  35. #endif
  36. #include <map>
  37. #include <string>
  38. #include <vector>
  39. #include <stdio.h>
  40. #include <stdarg.h>
  41. #include <stdlib.h>
  42. class PBuffer;
  43. class Console;
  44. class Frustum;
  45. class Bsp;
  46. class Mesh;
  47. class Light;
  48. class Fog;
  49. class Mirror;
  50. class Shader;
  51. class Texture;
  52. class Material;
  53. #include "mathlib.h"
  54. #include "bsp.h"
  55. #include "position.h"
  56. #include "texture.h"
  57. #define ENGINE_SCREEN_MATERIAL "screen.mat"
  58. #define ENGINE_FONT_NAME "font.png"
  59. #define ENGINE_SPHERE_MESH "sphere.mesh"
  60. #define ENGINE_SHADOW_VOLUME_SHADER "shadow_volume.shader"
  61. #define ENGINE_LOG_NAME "Engine.log"
  62. #define ENGINE_GAP_SIZE 256
  63. class Engine {
  64. public:
  65. static int init(const char *config = NULL);
  66. static void clear();
  67. static int match(const char *mask,const char *name);
  68. static void addPath(const char *path);
  69. static const char *findFile(const char *name);
  70. static void define(const char *define);
  71. static void undef(const char *define);
  72. static int isDefine(const char *define);
  73. // loaders
  74. static void load(const char *name);
  75. static Shader *loadShader(const char *name);
  76. static Texture *loadTexture(const char *name,GLuint target = Texture::TEXTURE_2D,int flag = texture_filter);
  77. static Material *loadMaterial(const char *name);
  78. static Mesh *loadMesh(const char *name);
  79. static void reload();
  80. static void reload_shaders();
  81. static void reload_textures();
  82. static void reload_materials();
  83. static void setExternLoad(void (*func)(void*),void *data);
  84. static void addObject(Object *object);
  85. static void removeObject(Object *object);
  86. static void addLight(Light *light);
  87. static void removeLight(Light *light);
  88. static void addFog(Fog *fog);
  89. static void removeFog(Fog *fog);
  90. static void addMirror(Mirror *mirror);
  91. static void removeMirror(Mirror *mirror);
  92. static void update(float ifps);
  93. // renderers
  94. static void render_light();
  95. static void render_transparent();
  96. static void render(float ifps);
  97. // intersection line with scene
  98. static Object *intersection(const vec3 &line0,const vec3 &line1,vec3 &point,vec3 &normal);
  99. // renderer info
  100. static char *vendor;
  101. static char *renderer;
  102. static char *version;
  103. static char *extensions;
  104. // screen
  105. static int screen_width;
  106. static int screen_height;
  107. static int screen_multisample;
  108. static PBuffer *screen;
  109. static Texture *screen_texture;
  110. static Material *screen_material;
  111. // console
  112. static Console *console;
  113. // objects
  114. static Position camera;
  115. static Frustum *frustum;
  116. static Bsp *bsp;
  117. static int num_objects;
  118. static Object **objects;
  119. // lights
  120. static int num_lights;
  121. static Light **lights;
  122. static int num_visible_lights;
  123. static Light **visible_lights;
  124. static Light *current_light;
  125. // fogs
  126. static int num_fogs;
  127. static Fog **fogs;
  128. static int num_visible_fogs;
  129. static Fog **visible_fogs;
  130. static Fog *current_fog;
  131. // mirrors
  132. static int num_mirrors;
  133. static Mirror **mirrors;
  134. static int num_visible_mirrors;
  135. static Mirror **visible_mirrors;
  136. static Mirror *current_mirror;
  137. // occlusion test
  138. static GLuint query_id;
  139. static Mesh *sphere_mesh;
  140. // shadow volume
  141. static Shader *shadow_volume_shader;
  142. // current state
  143. static float time;
  144. static vec4 light;
  145. static vec4 light_color;
  146. static vec4 fog_color;
  147. static int viewport[4];
  148. static mat4 projection;
  149. static mat4 modelview;
  150. static mat4 imodelview;
  151. static mat4 transform;
  152. static mat4 itransform;
  153. // 1.0f / fps
  154. static float ifps;
  155. // current frame
  156. static int frame;
  157. // all triangles
  158. static int num_triangles;
  159. // renderer abilities
  160. static int have_occlusion;
  161. static int have_stencil_two_side;
  162. // engine toggles
  163. static int wareframe_toggle;
  164. static int scissor_toggle;
  165. static int shadows_toggle;
  166. static int show_shadows_toggle;
  167. static int fog_toggle;
  168. static int mirror_toggle;
  169. static int physic_toggle;
  170. // path
  171. static std::vector<char*> path;
  172. // defines
  173. static std::vector<char*> defines;
  174. // default texture filter
  175. static int texture_filter;
  176. // object managment
  177. static std::map<std::string,Shader*> shaders;
  178. static std::map<std::string,Texture*> textures;
  179. static std::map<std::string,Material*> materials;
  180. static std::map<std::string,Mesh*> meshes;
  181. static void (*extern_load)(void*);
  182. static void *extern_load_data;
  183. // new stderr descriptor
  184. static int stderr_fd;
  185. };
  186. #endif /* __ENGINE_H__ */