zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Video_GL_Shader.cpp
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2  * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3  *
4  * zenilib is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * zenilib is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <zeni_graphics.h>
19 
20 #ifndef DISABLE_GL
21 
22 #if defined(REQUIRE_GL_ES)
23 #include <GLES/gl.h>
24 #else
25 #include <GL/glew.h>
26 #endif
27 
28 #include <SDL/SDL.h>
29 #ifndef TEMP_DISABLE
30 #ifdef REQUIRE_GL_ES
31 #include <SDL/SDL_opengles.h>
32 #else
33 namespace SDLOPENGL {
34 #include <SDL/SDL_opengl.h>
35 }
36 #endif
37 #endif
38 
39 #ifdef _LINUX
40 namespace GLXEW {
41 #include <GL/glxew.h>
42 }
43 #endif
44 
45 #include <GLSLANG/ShaderLang.h>
46 
47 #include <iostream>
48 
49 #if defined(_DEBUG) && defined(_WINDOWS)
50 #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
51 #define new DEBUG_NEW
52 #endif
53 
54 #ifndef TEMP_DISABLE
55 #ifdef REQUIRE_GL_ES
56 extern "C" GL_API int GL_APIENTRY _dgles_load_library(void *, void *(*)(void *, const char *));
57 
58 static void * proc_loader(void *, const char * name) {
59  return SDL_GL_GetProcAddress(name);
60 }
61 #endif
62 #endif
63 
64 namespace Zeni {
65 
66  Video_GL_Shader::Video_GL_Shader()
67  :
68 #if SDL_VERSION_ATLEAST(1,3,0)
69  m_context(0),
70 #endif
71 #ifdef _LINUX
72  m_pglSwapIntervalEXT(0),
73 #endif
74  m_maximum_anisotropy(-1),
75  m_zwrite(false),
76  m_render_target(0)
77 #ifdef MANUAL_GL_VSYNC_DELAY
78  ,
79  m_buffer_swap_end_time(0u),
80  m_time_taken(0.0f),
81  m_weight_new(0.2f)
82 #endif
83  {
84  init();
85  }
86 
87  Video_GL_Shader::~Video_GL_Shader() {
88  uninit();
89  }
90 
92  assert(!m_render_target);
93 
94 #ifdef _WINDOWS
95  glFlush();
96 #else
97  glFinish();
98 #endif
99 
102 
103  return true;
104  }
105 
107  assert(!m_render_target);
108 
109  glViewport(0, 0, get_Window().get_width(), get_Window().get_height());
110 
111  if(!is_zwrite_enabled())
115  if(!is_zwrite_enabled())
117 
118  return true;
119  }
120 
122  /*** Begin CPU saver ***/
123 #ifdef MANUAL_GL_VSYNC_DELAY
124  Timer &tr = get_Timer();
125 
126  if(get_vertical_sync()) {
127  Time buffer_swap_start_time = tr.get_time();
128 
129  const unsigned int time_allowed = 1000u/60u - 2u;
130  const unsigned int new_time_taken = buffer_swap_start_time.get_ticks_since(m_buffer_swap_end_time);
131  m_time_taken = (1.0f - m_weight_new) * m_time_taken + m_weight_new * new_time_taken;
132 
133  if(m_time_taken < time_allowed)
134  SDL_Delay(static_cast<unsigned int>(time_allowed - m_time_taken));
135  }
136 #endif
137 
139 #ifndef TEMP_DISABLE
140 #if SDL_VERSION_ATLEAST(1,3,0)
141  SDL_GL_SwapWindow(get_Window().get_window());
142 #else
143  SDL_GL_SwapBuffers();
144 #endif
145 #endif
146 
147 #ifdef MANUAL_GL_VSYNC_DELAY
148  m_buffer_swap_end_time = tr.get_time();
149 #endif
150  }
151 
152 #if SDL_VERSION_ATLEAST(1,3,0)
153  void Video_GL_Shader::alert_window_destroyed() {
154  m_context = 0;
155  }
156 #endif
157 
158  void Video_GL_Shader::render(const Renderable &renderable) {
159  class PrePostRenderActor {
160  PrePostRenderActor & operator=(const PrePostRenderActor &) {return *this;}
161 
162  public:
163  PrePostRenderActor(const Renderable &renderable_)
164  : renderable(renderable_)
165  {
166  renderable.pre_render();
167  }
168 
169  ~PrePostRenderActor() {
170  renderable.post_render();
171  }
172  private:
173  const Renderable &renderable;
174  } ppra(renderable);
175 
176  renderable.render_to(*this);
177  }
178 
180  if(!is_zwrite_enabled())
183  if(!is_zwrite_enabled())
185  }
186 
188  return m_maximum_anisotropy;
189  }
190 
192  return GLEW_ARB_vertex_buffer_object != 0;
193  }
194 
195  void Video_GL_Shader::set_2d_view(const std::pair<Point2f, Point2f> &camera2d, const std::pair<Point2i, Point2i> &viewport, const bool &fix_aspect_ratio) {
196  Video::set_2d_view(camera2d, viewport, fix_aspect_ratio);
197 
198  if(m_render_target) {
200  translate_scene(Vector3f(0.0f, camera2d.second.y, 0.0f));
201  scale_scene(Vector3f(1.0f, -1.0f, 1.0f));
202  translate_scene(Vector3f(0.0f, -camera2d.first.y, 0.0f));
203 
206  }
207  else if(get_backface_culling())
209  }
210 
211  void Video_GL_Shader::set_3d_view(const Camera &camera, const std::pair<Point2i, Point2i> &viewport) {
212  Video::set_3d_view(camera, viewport);
213 
214  if(m_render_target) {
217  }
218  else if(get_backface_culling())
220  }
221 
224 
225  if(on) {
226  // Enable Backface Culling
228 
229  if(m_render_target)
231  else
233  }
234  else
236  }
237 
238  void Video_GL_Shader::set_vertical_sync(const bool &on_) {
241 
242 #ifdef MANUAL_GL_VSYNC_DELAY
243  const bool on = false;
244 #else
245  const bool on = on_;
246 #endif
247 
248 #ifndef TEMP_DISABLE
249 #if SDL_VERSION_ATLEAST(1,3,0)
251 #elif !defined(DISABLE_WGL)
252  typedef BOOL (APIENTRY *PFNWGLSWAPINTERVALFARPROC)(int);
253  PFNWGLSWAPINTERVALFARPROC wglSwapIntervalEXT = 0;
254 
255  const char *extensions = reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS));
256 
257  if(strstr(extensions, "WGL_EXT_swap_control")) {
258  wglSwapIntervalEXT = (PFNWGLSWAPINTERVALFARPROC)wglGetProcAddress("wglSwapIntervalEXT");
259 
260  if(wglSwapIntervalEXT)
261  wglSwapIntervalEXT(on);
262  }
263 #elif defined(_LINUX)
264  if(m_pglSwapIntervalSGI)
265  m_pglSwapIntervalSGI(on);
266  else if(m_pglSwapIntervalEXT)
267  m_pglSwapIntervalEXT(0, 0, on);
268  else
269  SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, on);
270 #else
271  SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, on);
272 #endif
273 #endif
274 
275  SDL_ClearError();
276  }
277 
279  Video::set_zwrite(enabled);
280 
281  glDepthMask(GLboolean(enabled));
282  }
283 
285  Video::set_ztest(enabled);
286 
287  if(enabled) {
290  }
291  else
293  }
294 
296  const TEST &test,
297  const float &value)
298  {
299  Video::set_alpha_test(enabled, test, value);
300 
301  GLenum func;
302 
303  switch(test) {
304  case ZENI_NEVER: func = GL_NEVER; break;
305  case ZENI_LESS: func = GL_LESS; break;
306  case ZENI_EQUAL: func = GL_EQUAL; break;
307  case ZENI_GREATER: func = GL_GREATER; break;
308  case ZENI_NOT_EQUAL: func = GL_NOTEQUAL; break;
309  case ZENI_LESS_OR_EQUAL: func = GL_LEQUAL; break;
310  case ZENI_GREATER_OR_EQUAL: func = GL_GEQUAL; break;
311  case ZENI_ALWAYS: func = GL_ALWAYS; break;
312  default:
313  assert(false);
314  return;
315  }
316 
317  if(enabled)
319  else
321 
322  glAlphaFunc(func, value);
323  }
324 
326  Video::set_Color(color);
327 
328  glColor4f(color.r, color.g, color.b, color.a);
329  }
330 
332  Video::set_clear_Color(color);
333 
334  glClearColor(color.r, color.g, color.b, color.a);
335  }
336 
337  void Video_GL_Shader::apply_Texture(const unsigned long &id) {
339  }
340 
342  texture.apply_Texture();
343  }
344 
347  }
348 
349  void Video_GL_Shader::set_lighting(const bool &on) {
351 
352  if(on)
354  else
356  }
357 
360 
361  glLightModelfv(GL_LIGHT_MODEL_AMBIENT, reinterpret_cast<const GLfloat *>(&color));
362  }
363 
364  void Video_GL_Shader::set_Light(const int &number, const Light &light) {
365  GLenum ln;
366  switch(number) {
367  case 0: ln = GL_LIGHT0; break;
368  case 1: ln = GL_LIGHT1; break;
369  case 2: ln = GL_LIGHT2; break;
370  case 3: ln = GL_LIGHT3; break;
371  case 4: ln = GL_LIGHT4; break;
372  case 5: ln = GL_LIGHT5; break;
373  case 6: ln = GL_LIGHT6; break;
374  case 7: ln = GL_LIGHT7; break;
375  default:
376  throw Light_Out_of_Range();
377  }
378 
379  Video::set_Light(number, light);
380 
381  light.set(ln, *this);
382  }
383 
384  void Video_GL_Shader::unset_Light(const int &number) {
385  GLenum ln;
386  switch(number) {
387  case 0: ln = GL_LIGHT0; break;
388  case 1: ln = GL_LIGHT1; break;
389  case 2: ln = GL_LIGHT2; break;
390  case 3: ln = GL_LIGHT3; break;
391  case 4: ln = GL_LIGHT4; break;
392  case 5: ln = GL_LIGHT5; break;
393  case 6: ln = GL_LIGHT6; break;
394  case 7: ln = GL_LIGHT7; break;
395  default:
396  throw Light_Out_of_Range();
397  }
398 
399  Video::unset_Light(number);
400 
401  glDisable(ln);
402  }
403 
404  void Video_GL_Shader::set_Material(const Material &material) {
405  material.set(*this);
406  }
407 
409  material.unset(*this);
410  }
411 
412  void Video_GL_Shader::set_Fog(const Fog &fog) {
413  Video::set_Fog(fog);
414 
415  glEnable(GL_FOG);
416  fog.set(*this);
417  }
418 
421 
422  glDisable(GL_FOG);
423  }
424 
426  program.link();
427  glUseProgram(dynamic_cast<Program_GL_Shader &>(program).get());
428  }
429 
431  glUseProgram(0);
432  }
433 
435 #if !defined(REQUIRE_GL_ES) || defined(GL_OES_VERSION_2_0)
436  texture
437 #endif
438  )
439  {
440 #if defined(REQUIRE_GL_ES) && !defined(GL_OES_VERSION_2_0)
442 #else
443  if(m_render_target)
445 
446  Texture_GL &tgl = dynamic_cast<Texture_GL &>(texture);
447 
448  if(!tgl.m_frame_buffer_object) {
449  const Point2i &tex_size = tgl.get_size();
450 
451  // Generate Depth Buffer
452  glGenRenderbuffersEXT(1, &tgl.m_render_buffer);
453  glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, tgl.m_render_buffer);
456 
457  // Generate Framebuffer Object
458  glGenFramebuffersEXT(1, &tgl.m_frame_buffer_object);
459  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, tgl.m_frame_buffer_object);
460 
461  // Bind Both to the Texture
464  }
465  else
466  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, tgl.m_frame_buffer_object);
467 
468  m_render_target = &tgl;
469 #endif
470  }
471 
473 #if defined(REQUIRE_GL_ES) && !defined(GL_OES_VERSION_2_0)
475 #else
476  if(!m_render_target)
478 
479  // Unbind all
481 
482  // Prepare to Generate Mipmap
483  glBindTexture(GL_TEXTURE_2D, m_render_target->m_texture_id);
487 
489 
490  // Cleanup after Mipmap Generation
494  (Textures::get_bilinear_filtering() ? GL_LINEAR : GL_NEAREST));
497 
498  m_render_target = 0;
499 #endif
500  }
501 
503  set_clear_Color(color);
505  }
506 
508  if(m_render_target)
509  return m_render_target->get_size();
510  else
511  return get_Window().get_size();
512  }
513 
516  }
517 
520  glPushMatrix();
521  }
522 
525  glPopMatrix();
526  }
527 
529  glTranslatef(direction.i, direction.j, direction.k);
530  }
531 
532  void Video_GL_Shader::rotate_scene(const Vector3f &about, const float &radians) {
533  glRotatef(radians * 180.0f / Global::pi, about.i, about.j, about.k);
534  }
535 
537  glScalef(factor.i, factor.j, factor.k);
538  }
539 
540  void Video_GL_Shader::transform_scene(const Matrix4f &transformation) {
541  glMultMatrixf(reinterpret_cast<const GLfloat * const>(&transformation));
542  }
543 
545  return Point2f(0.0f, 0.0f);
546  }
547 
550 
552  glLoadMatrixf(reinterpret_cast<GLfloat *>(const_cast<Matrix4f *>(&view)));
553  }
554 
556  Video::set_projection_matrix(projection);
557 
559  if(m_render_target && is_3d()) {
560  const Matrix4f flipped = Matrix4f::Scale(Vector3f(1.0f, -1.0f, 1.0f)) * projection;
561  glLoadMatrixf(reinterpret_cast<GLfloat *>(const_cast<Matrix4f *>(&flipped)));
562  }
563  else
564  glLoadMatrixf(reinterpret_cast<GLfloat *>(const_cast<Matrix4f *>(&projection)));
565  }
566 
567  void Video_GL_Shader::set_viewport(const std::pair<Point2i, Point2i> &viewport) {
568  Video::set_viewport(viewport);
569 
570  if(m_render_target)
571  glViewport(viewport.first.x, viewport.first.y, viewport.second.x - viewport.first.x, viewport.second.y - viewport.first.y);
572  else
573  glViewport(viewport.first.x, get_Window().get_height() - viewport.second.y, viewport.second.x - viewport.first.x, viewport.second.y - viewport.first.y);
574  }
575 
576  Texture * Video_GL_Shader::load_Texture(const String &filename, const bool &repeat, const bool &lazy_loading) {
577  return new Texture_GL(filename, repeat, lazy_loading);
578  }
579 
581  return new Texture_GL(image);
582  }
583 
584  Texture * Video_GL_Shader::create_Texture(const Point2i &size, const bool &repeat) {
585  return new Texture_GL(size, repeat);
586  }
587 
588  Font * Video_GL_Shader::create_Font(const String &filename, const float &glyph_height, const float &virtual_screen_height) {
589  return new Font_FT(filename, glyph_height, virtual_screen_height);
590  }
591 
593  return new Vertex_Buffer_Renderer_GL_Shader(vertex_buffer);
594  }
595 
598  }
599 
602  }
603 
605  return new Program_GL_Shader();
606  }
607 
610 
611  std::cerr << "Initializing OpenGL" << std::endl;
612 
613 #ifndef TEMP_DISABLE
614  //double buffer, no stencil, no accumulation buffer
626 
627  if(get_multisampling() > 1) {
630  }
631 
632 #ifdef REQUIRE_GL_ES
633  {
634  int err = _dgles_load_library(0, proc_loader);
635  if(err)
636  throw Video_Init_Failure();
637  }
638 #endif
639 
641 
642 #if SDL_VERSION_ATLEAST(2,0,0)
643  std::list<std::pair<int, int> > contexts;
644  contexts.push_back(std::make_pair(4, 4));
645  contexts.push_back(std::make_pair(4, 3));
646  contexts.push_back(std::make_pair(4, 2));
647  contexts.push_back(std::make_pair(4, 1));
648  contexts.push_back(std::make_pair(4, 0));
649  contexts.push_back(std::make_pair(3, 3));
650  contexts.push_back(std::make_pair(3, 2));
651 
652  while(!contexts.empty()) {
653  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, contexts.front().first);
654  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, contexts.front().second);
656  //SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
657 
658  m_context = SDL_GL_CreateContext(get_Window().get_window());
659  if(m_context)
660  break;
661 
662  std::cerr << "OpenGL context " << contexts.front().first << '.' << contexts.front().second << " failed." << std::endl;
663  SDL_ClearError();
664  contexts.pop_front();
665  }
666 
667  if(!m_context)
668  throw Video_Init_Failure();
669 
670  /* This had to be before SDL_GL_CreateContext to work correctly on OS X some time ago.
671  * Now it causes an error to be before. Test.
672  */
675  SDL_ClearError();
676 #endif
677 
679 
680 #ifndef REQUIRE_GL_ES
681  {
682  const GLenum err = glewInit();
683  if(GLEW_OK != err) {
684  std::cerr << "GLEW Error: " << glewGetErrorString(err) << std::endl;
685  throw Video_Init_Failure();
686  }
687  }
688 #endif
689 #endif
690 
692 
693  // Set Fill/Shade Mode
695 #ifndef REQUIRE_GL_ES
697 #endif
698  glEnable(GL_NORMALIZE); //GL_RESCALE_NORMALIZE);
699 
700  // Enable Alpha Blitting
703  //glBlendEquation(GL_FUNC_ADD); // default // would require ARB ext
704 
705  // Set lighting variables
706 #ifndef REQUIRE_GL_ES
709  if(glGetError() == GL_INVALID_ENUM)
710  std::cerr << "Quality Warning: Your graphics card does not support separate specular lighting in OpenGL.\n";
711 #endif
712 
713  // Initialize Assorted Variables
714  glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
715  //glPointSize(static_cast<GLfloat>(sqrt(pow(double(get_screen_width()), 2.) * pow(double(get_screen_height()), 2.)) / 1000000));
716  //glLineWidth(static_cast<GLfloat>(sqrt(pow(double(get_screen_width()), 2.) * pow(double(get_screen_height()), 2.)) / 1000000));
717 
719 
720  // Finish with a few function calls
721  set_2d();
722  set_Color(get_Color());
727  for(int i = 0; i != 8; ++i)
728  if(const Light * const lp = get_Light(i))
729  set_Light(i, *lp);
730  if(const Fog * const fp = get_Fog())
731  set_Fog(*fp);
735 
737 
738 #ifndef REQUIRE_GL_ES
739 #ifdef _LINUX
740  union {
741  void * v;
742  GLXEW::PFNGLXSWAPINTERVALEXTPROC pglSwapIntervalEXT;
743  GLXEW::PFNGLXSWAPINTERVALSGIPROC pglSwapIntervalSGI;
744  } ptr;
745 
746  ptr.v = SDL_GL_GetProcAddress("glXSwapIntervalEXT");
747  if(!ptr.v)
748  ptr.v = SDL_GL_GetProcAddress("wglSwapIntervalEXT");
749  m_pglSwapIntervalEXT = ptr.pglSwapIntervalEXT;
750 
751  ptr.v = SDL_GL_GetProcAddress("glXSwapIntervalSGI");
752  if(!ptr.v)
753  ptr.v = SDL_GL_GetProcAddress("wglSwapIntervalSGI");
754  m_pglSwapIntervalSGI = ptr.pglSwapIntervalSGI;
755 #endif
756 
758  std::cerr << "Performance Warning: Your graphics card does not offer Vertex Buffer Objects (VBO) in OpenGL.\n";
759 
761  glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, reinterpret_cast<GLint *>(&m_maximum_anisotropy));
762  else
763  m_maximum_anisotropy = 0;
764 #else
765  m_maximum_anisotropy = 0;
766 #endif
767 
768  // Has to be done after finding the function pointer
770 
772 
773  ShBuiltInResources resources;
774  ShInitBuiltInResources(&resources);
775 
776  resources.MaxVertexAttribs = 8;
777  resources.MaxVertexUniformVectors = 128;
778  resources.MaxVaryingVectors = 8;
779  resources.MaxVertexTextureImageUnits = 0;
780  resources.MaxCombinedTextureImageUnits = 8;
781  resources.MaxTextureImageUnits = 8;
782  resources.MaxFragmentUniformVectors = 16;
783  resources.MaxDrawBuffers = 1;
784 
785  resources.OES_standard_derivatives = 0;
786  resources.OES_EGL_image_external = 0;
787 
790 
792  }
793 
797 
798 #if SDL_VERSION_ATLEAST(1,3,0)
799  if(m_context)
800  SDL_GL_DeleteContext(m_context);
801 #endif
802  }
803 
804 }
805 
806 #else
807 
808 namespace Zeni {
809  void * this_pointer_is_also_dead_beef = (void *)0xDEADBEEF;
810 }
811 
812 #endif
#define glDisable
Definition: gl_mangle.h:393
#define glTexParameteri
Definition: gl_mangle.h:1763
#define GL_TRUE
Definition: gl2.h:51
#define GL_FOG
Definition: glew_head.h:360
const Point2i & get_render_target_size() const
Get the dimensions of the render target.
virtual void link()=0
#define GL_FRONT
Definition: gl2.h:130
GL_APICALL void GL_APIENTRY glUseProgram(GLuint program)
void set_Color(const Color &color)
Set the current color.
An Abstraction of a Light.
Definition: Light.h:57
#define GLEW_EXT_texture_filter_anisotropic
Definition: glew.h:10087
#define GL_LINEAR_MIPMAP_LINEAR
Definition: gl2.h:316
virtual void set_lighting(const bool &on=true)=0
Set lighting on/off.
Definition: Video.cpp:218
const Color & get_clear_Color() const
Get the blank background color.
Definition: Video.hxx:114
Program * create_Program()
Create a Program from a file.
void set_backface_culling(const bool &on)
Set backface culling on/off.
#define GL_FALSE
Definition: gl2.h:50
#define GL_BLEND
Definition: gl2.h:147
void set_2d_view(const std::pair< Point2f, Point2f > &, const std::pair< Point2i, Point2i > &=std::make_pair(Point2i(), get_Video().get_render_target_size()), const bool &fix_aspect_ratio=false)
Set a 2D view for a viewport.
#define GL_CULL_FACE
Definition: gl2.h:146
static void assert_no_error()
If there is an SDL error, print it and assert(false)
Definition: Core.cpp:122
#define wglSwapIntervalEXT
Definition: wglew.h:716
DECLSPEC void *SDLCALL SDL_GL_GetProcAddress(const char *proc)
Get the address of an OpenGL function.
Definition: SDL_video.c:2340
virtual void set_vertical_sync(const bool &on)=0
Set vertical_sync on/off.
Definition: Video.cpp:190
const GLubyte GLuint GLuint GLuint GLuint alpha GLboolean GLboolean GLboolean GLboolean alpha GLint GLint GLsizei GLsizei GLenum type GLenum GLint GLenum GLint GLint GLsizei GLsizei GLint border GLenum GLint GLint GLint GLint GLint GLsizei GLsizei height GLsizei GLsizei GLenum GLenum const GLvoid *pixels GLenum GLint GLint GLint GLint j2 GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble zFar GLenum light
Definition: SDL_glfuncs.h:144
#define glLightModelfv
Definition: gl_mangle.h:990
GLuint color
Definition: glew.h:7185
unsigned int GLenum
Definition: gl2.h:23
Camera / Point of View.
Definition: Camera.h:49
virtual void post_render() const
Definition: Renderable.cpp:61
virtual void render_to(Video_GL_Fixed &screen) const =0
Overridden for OpenGL rendering.
#define glPolygonMode
Definition: gl_mangle.h:1295
#define GL_SRC_ALPHA
Definition: gl2.h:77
#define glCullFace
Definition: gl_mangle.h:332
GLclampf f
Definition: glew.h:3390
unsigned char GLboolean
Definition: gl2.h:24
void set_view_matrix(const Matrix4f &view)
Set the view Matrix4f.
DECLSPEC SDL_GLContext SDLCALL SDL_GL_CreateContext(SDL_Window *window)
Create an OpenGL context for use with an OpenGL window, and make it current.
Definition: SDL_video.c:2758
#define GL_LIGHT6
Definition: glew_head.h:674
virtual void set_view_matrix(const Matrix4f &view)=0
Set the view Matrix4f.
Definition: Video.cpp:226
virtual void set_clear_Color(const Color &color)=0
Set the blank background color.
Definition: Video.cpp:214
virtual void unset_Fog()=0
Unset Fog.
Definition: Video.cpp:300
#define GL_BACK
Definition: gl2.h:131
GLenum GLsizei const GLuint GLboolean enabled
Definition: glew.h:2538
#define GL_EQUAL
Definition: gl2.h:283
#define GL_TEXTURE_2D
Definition: gl2.h:145
#define GL_NORMALIZE
Definition: glew_head.h:383
void translate_scene(const Vector3f &direction)
Translate the scene.
static bool get_backface_culling()
Determine whether backface culling is enabled.
Definition: Video.hxx:37
const Light * get_Light(const int &number) const
Get pointer to Light, or 0 if no such Light.
Definition: Video.cpp:274
static bool get_lighting()
Determine whether dynamic lighting is enabled.
Definition: Video.hxx:41
COMPILER_EXPORT ShHandle ShConstructCompiler(ShShaderType type, ShShaderSpec spec, ShShaderOutput output, const ShBuiltInResources *resources)
Definition: ShaderLang.cpp:140
void apply_Texture(const String &name)
Apply a texture by name.
virtual void set_Light(const int &number, const Light &light)=0
Set a particular Light.
Definition: Video.cpp:283
#define glGetIntegerv
Definition: gl_mangle.h:679
int MaxFragmentUniformVectors
Definition: ShaderLang.h:212
bool begin_prerender()
Must be called before begin_render.
#define GL_DEPTH_COMPONENT16
Definition: gl2.h:433
void transform_scene(const Matrix4f &transformation)
Transform the scene.
int MaxVertexTextureImageUnits
Definition: ShaderLang.h:209
An Abstraction of a Material.
Definition: Material.h:56
void set_lighting(const bool &on=true)
Set lighting on/off.
#define glBindFramebufferEXT
Definition: glew.h:8999
#define glTranslatef
Definition: gl_mangle.h:1802
#define GL_LIGHT4
Definition: glew_head.h:672
#define GL_FRONT_AND_BACK
Definition: gl2.h:132
EGLImageKHR EGLint * name
Definition: eglext.h:284
bool is_alpha_test_enabled() const
Determine whether alpha testing is enabled.
Definition: Video.hxx:69
#define GL_LIGHT3
Definition: glew_head.h:671
void set_Fog(const Fog &fog)
Set Fog.
Shader * create_Vertex_Shader(const String &filename)
Create a Vertex Shader from a file.
void set(const GLenum &number, Video_GL_Fixed &screen) const
Definition: Light.cpp:52
Tick_Type get_ticks_since(const Time &time) const
Get the number of clock ticks passed between &#39;time&#39; and this Time.
Definition: Timer.hxx:40
TEST get_alpha_test_function() const
Determine which alpha test is in use.
Definition: Video.hxx:73
#define assert(x)
Definition: SDL_malloc.c:1234
#define GL_LIGHTING
Definition: glew_head.h:352
void set_clear_Color(const Color &color)
Set the blank background color.
virtual void set_zwrite(const bool &enabled)=0
Enable or disable writing to the Z-Buffer.
Definition: Video.cpp:194
String compile_glsles_shader(const String &filename, const ShHandle &compiler)
Compile an OpenGL ES shader to GLSL/HLSL.
Definition: Video.cpp:304
void set_zwrite(const bool &enabled)
Enable or disable writing to the Z-Buffer.
bool begin_render()
Must be called before all rendering functions; Returns true if rendering can proceed.
A Renderable Interface.
Definition: Renderable.h:47
if(!yyg->yy_init)
GLenum func
Definition: SDL_opengl.h:5654
#define GL_DEPTH_ATTACHMENT_EXT
Definition: glew.h:8963
ShHandle m_vertex_compiler
Definition: Video.h:243
bool is_3d() const
Determine whether currently rendering in 3D.
Definition: Video.hxx:81
Image.
Definition: Image.h:52
void set_ambient_lighting(const Color &color)
Set ambient lighting on/off.
EGLImageKHR image
Definition: eglext.h:88
void set(Video_GL_Fixed &screen) const
Definition: Fog.cpp:48
#define SDL_VERSION_ATLEAST(X, Y, Z)
Definition: SDL_version.h:106
void unset_Material(const Material &material)
Unset a Material.
#define glClear
Definition: gl_mangle.h:170
#define glFlush
Definition: gl_mangle.h:485
void unset_program()
Disable a program.
#define glFramebufferRenderbufferEXT
Definition: glew.h:9004
void end_render()
Must be called after all rendering functions.
#define GL_LESS
Definition: gl2.h:282
bool has_vertex_buffers() const
Determine whether Vertex_Buffers are supported.
bool is_zwrite_enabled() const
Determine whether writing to Z-Buffer is enabled.
Definition: Video.hxx:61
DECLSPEC int SDLCALL SDL_GL_SetAttribute(SDL_GLattr attr, int value)
Set an OpenGL window attribute before window creation.
Definition: SDL_video.c:2469
#define glPushMatrix
Definition: gl_mangle.h:1476
#define GL_COLOR_BUFFER_BIT
Definition: gl2.h:47
void set_ztest(const bool &enabled)
Enable or disable testing of the Z-Buffer.
An Abstraction of a Texture.
Definition: Texture.h:61
Timer & get_Timer()
Get access to the singleton.
Definition: Timer.cpp:73
A Featureful 3-Space Vector Class.
Definition: Vector3f.h:58
#define glRotatef
Definition: gl_mangle.h:1555
#define glFinish
Definition: gl_mangle.h:482
ALuint u
Definition: alMain.h:58
virtual void set_ztest(const bool &enabled)=0
Enable or disable testing of the Z-Buffer.
Definition: Video.cpp:198
#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
Definition: gl2ext.h:406
#define GL_TEXTURE_MIN_FILTER
Definition: gl2.h:320
DECLSPEC int SDLCALL SDL_GL_SetSwapInterval(int interval)
Set the swap interval for the current OpenGL context.
Definition: SDL_video.c:2843
const GLdouble * v
Definition: glew.h:1377
void unset_Light(const int &number)
Unset a particular Light.
#define glScalef
Definition: gl_mangle.h:1572
#define APIENTRY
Definition: glew_head.h:150
virtual void set_ambient_lighting(const Color &color)=0
Set ambient lighting on/off.
Definition: Video.cpp:222
void unset(Video_GL_Fixed &screen) const
Definition: Material.cpp:115
void set_render_target(Texture &texture)
Set a render target.
int
Definition: SDL_systhread.c:37
#define glViewport
Definition: gl_mangle.h:2242
A Timer Singleton.
Definition: Timer.h:97
const float pi
pi == 3.1415926...
Definition: Vector3f.cpp:27
An Abstraction of Fog.
Definition: Fog.h:47
void render(const Renderable &renderable)
Render a Renderable.
void select_world_matrix()
Select the world (model view) matrix; Call before [translate/rotate/scale] scene. ...
#define GL_NEVER
Definition: gl2.h:281
float a
Definition: Color.h:69
static const Color & get_ambient_lighting()
Get the current ambient lighting Color.
Definition: Video.hxx:45
virtual void set_3d_view(const Camera &camera, const std::pair< Point2i, Point2i > &viewport=std::make_pair(Point2i(), get().get_render_target_size()))=0
Set a 3D view for a viewport.
Definition: Video.cpp:174
#define GL_RENDERBUFFER_EXT
Definition: glew.h:8966
COMPILER_EXPORT void ShDestruct(ShHandle handle)
Definition: ShaderLang.cpp:158
COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources *resources)
Definition: ShaderLang.cpp:109
#define GL_ALPHA_TEST
Definition: glew_head.h:393
void set_3d_view(const Camera &, const std::pair< Point2i, Point2i > &=std::make_pair(Point2i(), get_Video().get_render_target_size()))
Set a 3D view for a viewport.
#define glShadeModel
Definition: gl_mangle.h:1626
#define glEnable
Definition: gl_mangle.h:441
#define GL_LIGHT_MODEL_COLOR_CONTROL
Definition: glew.h:1226
DECLSPEC void SDLCALL SDL_GL_DeleteContext(SDL_GLContext context)
Delete an OpenGL context.
Definition: SDL_video.c:2889
void unapply_Texture()
Unapply a texture.
void set_2d()
Set the default 2D view filling the entire display area.
Definition: Video.hxx:93
void set_vertical_sync(const bool &on)
Set vertical_sync on/off.
#define GLEW_OK
Definition: glew_tail.h:4
void clear_render_target(const Color &color=Color(0.0f, 0.0f, 0.0f, 0.0f))
Clear the viewport.
#define GL_MODELVIEW
Definition: glew_head.h:581
#define glLightModeli
Definition: gl_mangle.h:991
DECLSPEC void SDLCALL SDL_Delay(Uint32 ms)
Wait a specified number of milliseconds before returning.
Definition: SDL_systimer.c:70
void pop_world_stack()
Pop a model view matrix off the stack.
Time get_time()
Get the current Time.
Definition: Timer.hxx:69
void rotate_scene(const Vector3f &about, const float &radians)
Rotate the scene.
#define GL_LIGHT1
Definition: glew_head.h:669
static int get_multisampling()
Get the current level of multisampling.
Definition: Video.hxx:57
Font Abstraction.
Definition: Font.h:70
void set_Material(const Material &material)
Set a Material.
virtual void set_Color(const Color &color)=0
Set the current color.
Definition: Video.cpp:210
#define glGenerateMipmapEXT
Definition: glew.h:9010
Texture * load_Texture(const String &filename, const bool &repeat, const bool &lazy_loading=false)
Function for loading a Texture; used internally by Textures.
void push_world_stack()
Push a model view matrix onto the stack.
#define glColor4f
Definition: gl_mangle.h:202
#define GL_FILL
Definition: glew_head.h:601
virtual void set_2d_view(const std::pair< Point2f, Point2f > &camera2d, const std::pair< Point2i, Point2i > &viewport=std::make_pair(Point2i(), get().get_render_target_size()), const bool &fix_aspect_ratio=false)=0
Set a 2D view for a viewport.
Definition: Video.cpp:153
#define glMultMatrixf
Definition: gl_mangle.h:1187
GLbitfield GLuint program
Definition: gl2ext.h:1203
void(* PFNGLXSWAPINTERVALEXTPROC)(Display *dpy, GLXDrawable drawable, int interval)
Definition: glxew.h:676
int(* PFNGLXSWAPINTERVALSGIPROC)(int interval)
Definition: glxew.h:1360
A Vertex_Buffer that accepts Triangle and Quadrilaterals.
Definition: Vertex_Buffer.h:85
void unset_Fog()
Unset Fog.
#define glGenFramebuffersEXT
Definition: glew.h:9008
#define glDepthFunc
Definition: gl_mangle.h:379
#define GL_LINEAR
Definition: gl2.h:308
void set(Video_GL_Fixed &screen) const
Definition: Material.cpp:83
virtual void set_Fog(const Fog &fog)=0
Set Fog.
Definition: Video.cpp:295
#define GL_FRAMEBUFFER_EXT
Definition: glew.h:8965
Textures & get_Textures()
Get access to the singleton.
Definition: Textures.cpp:64
const Point2i & get_size() const
Get the resolution of the Texture on the GPU.
Definition: Texture.hxx:48
#define GL_INVALID_ENUM
Definition: gl2.h:158
#define glDepthMask
Definition: gl_mangle.h:380
Window & get_Window()
Get access to the singleton.
Definition: Window.cpp:392
virtual void apply_Texture() const =0
Apply a Texture to upcoming polygons.
float b
Definition: Color.h:68
void apply_Texture(const String &name)
Apply a texture for upcoming polygons (Called by Video::apply_Texture)
Definition: Textures.cpp:68
#define GLEW_ARB_vertex_buffer_object
Definition: glew.h:6922
virtual void set_projection_matrix(const Matrix4f &projection)=0
Set the projection Matrix4f.
Definition: Video.cpp:230
int MaxCombinedTextureImageUnits
Definition: ShaderLang.h:210
virtual void set_viewport(const std::pair< Point2i, Point2i > &viewport=std::make_pair(Point2i(), get().get_render_target_size()))=0
Set the viewport.
Definition: Video.cpp:234
#define GL_COLOR_ATTACHMENT0_EXT
Definition: gl2ext.h:578
GLenum GLenum GLuint texture
Definition: gl2ext.h:850
#define glClearColor
Definition: gl_mangle.h:164
#define glPopMatrix
Definition: gl_mangle.h:1301
void unlose_resources()
If resources have been lost, then reload them.
Definition: Database.hxx:415
#define glLoadMatrixf
Definition: gl_mangle.h:1005
#define GL_LIGHT_MODEL_LOCAL_VIEWER
Definition: glew_head.h:353
#define glGetError
Definition: gl_mangle.h:643
EGLSurface EGLint void ** value
Definition: eglext.h:301
A base class for Vertex_Shader and Fragment_Shader.
Definition: Shader.h:97
void scale_scene(const Vector3f &factor)
Scale the scene.
void set_program(Program &program)
Enable a program.
#define GL_EXTENSIONS
Definition: gl2.h:304
DECLSPEC void SDLCALL SDL_ClearError(void)
Definition: SDL_error.c:212
void set_viewport(const std::pair< Point2i, Point2i > &viewport=std::make_pair(Point2i(), get_Video().get_render_target_size()))
Set the viewport.
#define glBindRenderbufferEXT
Definition: glew.h:9000
#define GL_GEQUAL
Definition: gl2.h:287
#define GL_PROJECTION
Definition: glew_head.h:582
#define GL_SMOOTH
Definition: glew_head.h:606
Font * create_Font(const String &filename, const float &glyph_height, const float &virtual_screen_height)
Function for creating a Font; used internally by Fonts.
#define GL_NOTEQUAL
Definition: gl2.h:286
#define glMatrixMode
Definition: gl_mangle.h:1053
const GLubyte *GLEWAPIENTRY glewGetErrorString(GLenum error)
Definition: glew_init_tail.c:3
#define GL_LIGHT_MODEL_AMBIENT
Definition: glew_head.h:355
Texture * create_Texture(const Image &image)
Function for creating a Texture from an Image.
#define GL_LIGHT7
Definition: glew_head.h:675
#define GL_ONE_MINUS_SRC_ALPHA
Definition: gl2.h:78
void set_Light(const int &number, const Light &light)
Set a particular Light.
#define GL_SEPARATE_SPECULAR_COLOR
Definition: glew.h:1228
static bool get_vertical_sync()
Determine whether vertical sync is enabled.
Definition: Video.hxx:53
#define GL_GREATER
Definition: gl2.h:285
virtual void set_backface_culling(const bool &on)=0
Set backface culling on/off.
Definition: Video.cpp:186
float g
Definition: Color.h:67
bool is_ztest_enabled() const
Determine whether testing the Z-Buffer is enabled.
Definition: Video.hxx:65
void set_projection_matrix(const Matrix4f &projection)
Set the projection Matrix4f.
static const Point2i & get_size()
Definition: Window.hxx:29
#define GL_LIGHT2
Definition: glew_head.h:670
#define GL_APIENTRY
Definition: gl2platform.h:27
#define GL_ALWAYS
Definition: gl2.h:288
Fonts & get_Fonts()
Get access to the singleton.
Definition: Fonts.cpp:60
#define glBindTexture
Definition: gl_mangle.h:98
const Color & get_Color() const
Get the current color.
Definition: Video.hxx:110
virtual void pre_render() const
Definition: Renderable.cpp:56
A Featureful 4-Space Matrix Class.
Definition: Matrix4f.h:47
static bool get_mipmapping()
Check if mipmapping is in use.
Definition: Textures.hxx:32
void clear_depth_buffer()
Can reset the depth buffer at any time if necessary.
float r
Definition: Color.h:66
int i
Definition: pngrutil.c:1377
virtual void set_alpha_test(const bool &enabled, const TEST &test=ZENI_ALWAYS, const float &value=0.0f)=0
Set the alpha test.
Definition: Video.cpp:202
virtual void unset_Light(const int &number)=0
Unset a particular Light.
Definition: Video.cpp:287
static bool get_bilinear_filtering()
Check if bilinear filtering is in use.
Definition: Textures.hxx:28
void unset_render_target()
Unset a render target.
#define GL_DEPTH_BUFFER_BIT
Definition: gl2.h:45
GLenum GLEWAPIENTRY glewInit(void)
#define GL_NEAREST_MIPMAP_NEAREST
Definition: gl2.h:313
ShHandle m_fragment_compiler
Definition: Video.h:244
A 2D Point represented with floats.
Definition: Coordinate.h:98
#define glGenRenderbuffersEXT
Definition: glew.h:9009
const Fog * get_Fog() const
Get pointer to current Fog, or 0 if no Fog.
Definition: Video.cpp:291
#define glAlphaFunc
Definition: gl_mangle.h:42
int get_maximum_anisotropy() const
Get the current level of anisotrophy.
#define GL_LIGHT5
Definition: glew_head.h:673
#define GL_LEQUAL
Definition: gl2.h:284
Shader * create_Fragment_Shader(const String &filename)
Create a Fragment_Shader from a file.
#define glRenderbufferStorageEXT
Definition: glew.h:9015
void set_alpha_test(const bool &enabled, const TEST &test, const float &value)
Set the alpha test.
static Matrix4f Scale(const Vector3f &scaling_factor)
Definition: Matrix4f.hxx:59
#define false
Definition: ftrandom.c:50
Vertex_Buffer_Renderer * create_Vertex_Buffer_Renderer(Vertex_Buffer &vertex_buffer)
Function for creating a Vertex_Buffer_Renderer.
#define GL_LIGHT0
Definition: glew_head.h:667
Color.
Definition: Color.h:41
DECLSPEC void SDLCALL SDL_GL_SwapWindow(SDL_Window *window)
Swap the OpenGL buffers for a window, if double-buffering is supported.
Definition: SDL_video.c:2871
#define glGetString
Definition: gl_mangle.h:824
int OES_standard_derivatives
Definition: ShaderLang.h:217
float get_alpha_test_value() const
Determine what value the alpha test is comparing against.
Definition: Video.hxx:77
#define GL_NEAREST
Definition: gl2.h:307
#define glBlendFunc
Definition: gl_mangle.h:135
Point2f get_pixel_offset() const
Get the pixel offset in the 2d view.
A Snapshot of the Timer.
Definition: Timer.h:63
#define glFramebufferTexture2DEXT
Definition: glew.h:9006
typedef BOOL(WINAPI *PFNWGLSETSTEREOEMITTERSTATE3DLPROC)(HDC hDC
#define GL_DEPTH_TEST
Definition: gl2.h:150
GLsizei size
Definition: gl2ext.h:1467
A 2D Point represented with integers.
Definition: Coordinate.h:85