22 #if defined(REQUIRE_GL_ES)
49 #if defined(_DEBUG) && defined(_WINDOWS)
50 #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
56 extern "C" GL_API
int GL_APIENTRY _dgles_load_library(
void *,
void *(*)(
void *,
const char *));
58 static void * proc_loader(
void *,
const char *
name) {
66 Video_GL_Shader::Video_GL_Shader()
72 m_pglSwapIntervalEXT(0),
74 m_maximum_anisotropy(-1),
77 #ifdef MANUAL_GL_VSYNC_DELAY
79 m_buffer_swap_end_time(0
u),
87 Video_GL_Shader::~Video_GL_Shader() {
123 #ifdef MANUAL_GL_VSYNC_DELAY
129 const unsigned int time_allowed = 1000
u/60
u - 2
u;
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;
133 if(m_time_taken < time_allowed)
134 SDL_Delay(static_cast<unsigned int>(time_allowed - m_time_taken));
140 #if SDL_VERSION_ATLEAST(1,3,0)
143 SDL_GL_SwapBuffers();
147 #ifdef MANUAL_GL_VSYNC_DELAY
148 m_buffer_swap_end_time = tr.
get_time();
152 #if SDL_VERSION_ATLEAST(1,3,0)
153 void Video_GL_Shader::alert_window_destroyed() {
159 class PrePostRenderActor {
160 PrePostRenderActor & operator=(
const PrePostRenderActor &) {
return *
this;}
163 PrePostRenderActor(
const Renderable &renderable_)
164 : renderable(renderable_)
169 ~PrePostRenderActor() {
188 return m_maximum_anisotropy;
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) {
198 if(m_render_target) {
214 if(m_render_target) {
242 #ifdef MANUAL_GL_VSYNC_DELAY
243 const bool on =
false;
249 #if SDL_VERSION_ATLEAST(1,3,0)
251 #elif !defined(DISABLE_WGL)
257 if(strstr(extensions,
"WGL_EXT_swap_control")) {
258 wglSwapIntervalEXT = (PFNWGLSWAPINTERVALFARPROC)wglGetProcAddress(
"wglSwapIntervalEXT");
260 if(wglSwapIntervalEXT)
263 #elif defined(_LINUX)
264 if(m_pglSwapIntervalSGI)
265 m_pglSwapIntervalSGI(on);
266 else if(m_pglSwapIntervalEXT)
267 m_pglSwapIntervalEXT(0, 0, on);
381 light.
set(ln, *
this);
409 material.
unset(*
this);
427 glUseProgram(dynamic_cast<Program_GL_Shader &>(program).
get());
435 #
if !defined(REQUIRE_GL_ES) || defined(GL_OES_VERSION_2_0)
440 #if defined(REQUIRE_GL_ES) && !defined(GL_OES_VERSION_2_0)
448 if(!tgl.m_frame_buffer_object) {
468 m_render_target = &tgl;
473 #if defined(REQUIRE_GL_ES) && !defined(GL_OES_VERSION_2_0)
541 glMultMatrixf(reinterpret_cast<const GLfloat * const>(&transformation));
552 glLoadMatrixf(reinterpret_cast<GLfloat *>(const_cast<Matrix4f *>(&view)));
559 if(m_render_target &&
is_3d()) {
561 glLoadMatrixf(reinterpret_cast<GLfloat *>(const_cast<Matrix4f *>(&flipped)));
564 glLoadMatrixf(reinterpret_cast<GLfloat *>(const_cast<Matrix4f *>(&projection)));
571 glViewport(viewport.first.x, viewport.first.y, viewport.second.x - viewport.first.x, viewport.second.y - viewport.first.y);
573 glViewport(viewport.first.x,
get_Window().get_height() - viewport.second.y, viewport.second.x - viewport.first.x, viewport.second.y - viewport.first.y);
577 return new Texture_GL(filename, repeat, lazy_loading);
589 return new Font_FT(filename, glyph_height, virtual_screen_height);
611 std::cerr <<
"Initializing OpenGL" << std::endl;
634 int err = _dgles_load_library(0, proc_loader);
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));
652 while(!contexts.empty()) {
662 std::cerr <<
"OpenGL context " << contexts.front().first <<
'.' << contexts.front().second <<
" failed." << std::endl;
664 contexts.pop_front();
680 #ifndef REQUIRE_GL_ES
695 #ifndef REQUIRE_GL_ES
706 #ifndef REQUIRE_GL_ES
710 std::cerr <<
"Quality Warning: Your graphics card does not support separate specular lighting in OpenGL.\n";
727 for(
int i = 0;
i != 8; ++
i)
738 #ifndef REQUIRE_GL_ES
749 m_pglSwapIntervalEXT = ptr.pglSwapIntervalEXT;
754 m_pglSwapIntervalSGI = ptr.pglSwapIntervalSGI;
758 std::cerr <<
"Performance Warning: Your graphics card does not offer Vertex Buffer Objects (VBO) in OpenGL.\n";
763 m_maximum_anisotropy = 0;
765 m_maximum_anisotropy = 0;
798 #if SDL_VERSION_ATLEAST(1,3,0)
809 void * this_pointer_is_also_dead_beef = (
void *)0xDEADBEEF;
const Point2i & get_render_target_size() const
Get the dimensions of the render target.
GL_APICALL void GL_APIENTRY glUseProgram(GLuint program)
void set_Color(const Color &color)
Set the current color.
An Abstraction of a Light.
#define GLEW_EXT_texture_filter_anisotropic
#define GL_LINEAR_MIPMAP_LINEAR
virtual void set_lighting(const bool &on=true)=0
Set lighting on/off.
const Color & get_clear_Color() const
Get the blank background color.
Program * create_Program()
Create a Program from a file.
void set_backface_culling(const bool &on)
Set backface culling on/off.
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.
static void assert_no_error()
If there is an SDL error, print it and assert(false)
#define wglSwapIntervalEXT
DECLSPEC void *SDLCALL SDL_GL_GetProcAddress(const char *proc)
Get the address of an OpenGL function.
virtual void set_vertical_sync(const bool &on)=0
Set vertical_sync on/off.
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
virtual void post_render() const
virtual void render_to(Video_GL_Fixed &screen) const =0
Overridden for OpenGL rendering.
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.
virtual void set_view_matrix(const Matrix4f &view)=0
Set the view Matrix4f.
virtual void set_clear_Color(const Color &color)=0
Set the blank background color.
virtual void unset_Fog()=0
Unset Fog.
GLenum GLsizei const GLuint GLboolean enabled
void translate_scene(const Vector3f &direction)
Translate the scene.
int MaxVertexUniformVectors
static bool get_backface_culling()
Determine whether backface culling is enabled.
const Light * get_Light(const int &number) const
Get pointer to Light, or 0 if no such Light.
static bool get_lighting()
Determine whether dynamic lighting is enabled.
COMPILER_EXPORT ShHandle ShConstructCompiler(ShShaderType type, ShShaderSpec spec, ShShaderOutput output, const ShBuiltInResources *resources)
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.
int MaxFragmentUniformVectors
bool begin_prerender()
Must be called before begin_render.
#define GL_DEPTH_COMPONENT16
void transform_scene(const Matrix4f &transformation)
Transform the scene.
int MaxVertexTextureImageUnits
An Abstraction of a Material.
void set_lighting(const bool &on=true)
Set lighting on/off.
#define glBindFramebufferEXT
#define GL_FRONT_AND_BACK
EGLImageKHR EGLint * name
bool is_alpha_test_enabled() const
Determine whether alpha testing is enabled.
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
Tick_Type get_ticks_since(const Time &time) const
Get the number of clock ticks passed between 'time' and this Time.
TEST get_alpha_test_function() const
Determine which alpha test is in use.
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.
String compile_glsles_shader(const String &filename, const ShHandle &compiler)
Compile an OpenGL ES shader to GLSL/HLSL.
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.
#define GL_DEPTH_ATTACHMENT_EXT
ShHandle m_vertex_compiler
bool is_3d() const
Determine whether currently rendering in 3D.
void set_ambient_lighting(const Color &color)
Set ambient lighting on/off.
void set(Video_GL_Fixed &screen) const
#define SDL_VERSION_ATLEAST(X, Y, Z)
void unset_Material(const Material &material)
Unset a Material.
void unset_program()
Disable a program.
#define glFramebufferRenderbufferEXT
void end_render()
Must be called after all rendering functions.
bool has_vertex_buffers() const
Determine whether Vertex_Buffers are supported.
bool is_zwrite_enabled() const
Determine whether writing to Z-Buffer is enabled.
DECLSPEC int SDLCALL SDL_GL_SetAttribute(SDL_GLattr attr, int value)
Set an OpenGL window attribute before window creation.
#define GL_COLOR_BUFFER_BIT
void set_ztest(const bool &enabled)
Enable or disable testing of the Z-Buffer.
An Abstraction of a Texture.
Timer & get_Timer()
Get access to the singleton.
A Featureful 3-Space Vector Class.
virtual void set_ztest(const bool &enabled)=0
Enable or disable testing of the Z-Buffer.
#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
#define GL_TEXTURE_MIN_FILTER
DECLSPEC int SDLCALL SDL_GL_SetSwapInterval(int interval)
Set the swap interval for the current OpenGL context.
void unset_Light(const int &number)
Unset a particular Light.
virtual void set_ambient_lighting(const Color &color)=0
Set ambient lighting on/off.
void unset(Video_GL_Fixed &screen) const
void set_render_target(Texture &texture)
Set a render target.
const float pi
pi == 3.1415926...
void render(const Renderable &renderable)
Render a Renderable.
void select_world_matrix()
Select the world (model view) matrix; Call before [translate/rotate/scale] scene. ...
static const Color & get_ambient_lighting()
Get the current ambient lighting Color.
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.
#define GL_RENDERBUFFER_EXT
COMPILER_EXPORT void ShDestruct(ShHandle handle)
COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources *resources)
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 GL_LIGHT_MODEL_COLOR_CONTROL
DECLSPEC void SDLCALL SDL_GL_DeleteContext(SDL_GLContext context)
Delete an OpenGL context.
void unapply_Texture()
Unapply a texture.
void set_2d()
Set the default 2D view filling the entire display area.
void set_vertical_sync(const bool &on)
Set vertical_sync on/off.
void clear_render_target(const Color &color=Color(0.0f, 0.0f, 0.0f, 0.0f))
Clear the viewport.
DECLSPEC void SDLCALL SDL_Delay(Uint32 ms)
Wait a specified number of milliseconds before returning.
void pop_world_stack()
Pop a model view matrix off the stack.
Time get_time()
Get the current Time.
void rotate_scene(const Vector3f &about, const float &radians)
Rotate the scene.
static int get_multisampling()
Get the current level of multisampling.
void set_Material(const Material &material)
Set a Material.
virtual void set_Color(const Color &color)=0
Set the current color.
#define glGenerateMipmapEXT
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.
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.
GLbitfield GLuint program
void(* PFNGLXSWAPINTERVALEXTPROC)(Display *dpy, GLXDrawable drawable, int interval)
int(* PFNGLXSWAPINTERVALSGIPROC)(int interval)
A Vertex_Buffer that accepts Triangle and Quadrilaterals.
void unset_Fog()
Unset Fog.
#define glGenFramebuffersEXT
void set(Video_GL_Fixed &screen) const
virtual void set_Fog(const Fog &fog)=0
Set Fog.
#define GL_FRAMEBUFFER_EXT
Textures & get_Textures()
Get access to the singleton.
const Point2i & get_size() const
Get the resolution of the Texture on the GPU.
Window & get_Window()
Get access to the singleton.
virtual void apply_Texture() const =0
Apply a Texture to upcoming polygons.
void apply_Texture(const String &name)
Apply a texture for upcoming polygons (Called by Video::apply_Texture)
#define GLEW_ARB_vertex_buffer_object
virtual void set_projection_matrix(const Matrix4f &projection)=0
Set the projection Matrix4f.
int MaxCombinedTextureImageUnits
virtual void set_viewport(const std::pair< Point2i, Point2i > &viewport=std::make_pair(Point2i(), get().get_render_target_size()))=0
Set the viewport.
#define GL_COLOR_ATTACHMENT0_EXT
GLenum GLenum GLuint texture
void unlose_resources()
If resources have been lost, then reload them.
#define GL_LIGHT_MODEL_LOCAL_VIEWER
EGLSurface EGLint void ** value
A base class for Vertex_Shader and Fragment_Shader.
void scale_scene(const Vector3f &factor)
Scale the scene.
void set_program(Program &program)
Enable a program.
DECLSPEC void SDLCALL SDL_ClearError(void)
void set_viewport(const std::pair< Point2i, Point2i > &viewport=std::make_pair(Point2i(), get_Video().get_render_target_size()))
Set the viewport.
#define glBindRenderbufferEXT
Font * create_Font(const String &filename, const float &glyph_height, const float &virtual_screen_height)
Function for creating a Font; used internally by Fonts.
const GLubyte *GLEWAPIENTRY glewGetErrorString(GLenum error)
#define GL_LIGHT_MODEL_AMBIENT
Texture * create_Texture(const Image &image)
Function for creating a Texture from an Image.
#define GL_ONE_MINUS_SRC_ALPHA
void set_Light(const int &number, const Light &light)
Set a particular Light.
#define GL_SEPARATE_SPECULAR_COLOR
static bool get_vertical_sync()
Determine whether vertical sync is enabled.
virtual void set_backface_culling(const bool &on)=0
Set backface culling on/off.
bool is_ztest_enabled() const
Determine whether testing the Z-Buffer is enabled.
void set_projection_matrix(const Matrix4f &projection)
Set the projection Matrix4f.
static const Point2i & get_size()
Fonts & get_Fonts()
Get access to the singleton.
const Color & get_Color() const
Get the current color.
virtual void pre_render() const
A Featureful 4-Space Matrix Class.
static bool get_mipmapping()
Check if mipmapping is in use.
void clear_depth_buffer()
Can reset the depth buffer at any time if necessary.
virtual void set_alpha_test(const bool &enabled, const TEST &test=ZENI_ALWAYS, const float &value=0.0f)=0
Set the alpha test.
virtual void unset_Light(const int &number)=0
Unset a particular Light.
static bool get_bilinear_filtering()
Check if bilinear filtering is in use.
void unset_render_target()
Unset a render target.
#define GL_DEPTH_BUFFER_BIT
int OES_EGL_image_external
GLenum GLEWAPIENTRY glewInit(void)
#define GL_NEAREST_MIPMAP_NEAREST
ShHandle m_fragment_compiler
A 2D Point represented with floats.
#define glGenRenderbuffersEXT
const Fog * get_Fog() const
Get pointer to current Fog, or 0 if no Fog.
int get_maximum_anisotropy() const
Get the current level of anisotrophy.
Shader * create_Fragment_Shader(const String &filename)
Create a Fragment_Shader from a file.
#define glRenderbufferStorageEXT
void set_alpha_test(const bool &enabled, const TEST &test, const float &value)
Set the alpha test.
static Matrix4f Scale(const Vector3f &scaling_factor)
Vertex_Buffer_Renderer * create_Vertex_Buffer_Renderer(Vertex_Buffer &vertex_buffer)
Function for creating a Vertex_Buffer_Renderer.
DECLSPEC void SDLCALL SDL_GL_SwapWindow(SDL_Window *window)
Swap the OpenGL buffers for a window, if double-buffering is supported.
int OES_standard_derivatives
float get_alpha_test_value() const
Determine what value the alpha test is comparing against.
Point2f get_pixel_offset() const
Get the pixel offset in the 2d view.
#define glFramebufferTexture2DEXT
typedef BOOL(WINAPI *PFNWGLSETSTEREOEMITTERSTATE3DLPROC)(HDC hDC
A 2D Point represented with integers.