Replaced glLoadGen loader with glad loader and dynamically load EGL and GLES extensions as is done for desktop GL.
This commit is contained in:
parent
f2b8e6397b
commit
2eb70c6537
44 changed files with 35003 additions and 3965 deletions
|
@ -1,5 +1,3 @@
|
|||
|
||||
|
||||
# CLI based examples
|
||||
if (NOT SFML_OS_IOS)
|
||||
if(SFML_BUILD_NETWORK)
|
||||
|
|
|
@ -7,4 +7,4 @@ set(SRC ${SRCROOT}/X11.cpp)
|
|||
# define the X11 target
|
||||
sfml_add_example(X11Example GUI_APP
|
||||
SOURCES ${SRC}
|
||||
DEPENDS sfml-window OpenGL X11)
|
||||
DEPENDS sfml-window X11)
|
||||
|
|
|
@ -4,7 +4,10 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <SFML/OpenGL.hpp>
|
||||
|
||||
#define GLAD_GL_IMPLEMENTATION
|
||||
#include "gl.h"
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
@ -23,7 +26,13 @@ void initialize(sf::Window& window)
|
|||
|
||||
// Setup OpenGL states
|
||||
// Set color and depth clear value
|
||||
|
||||
#ifdef SFML_OPENGL_ES
|
||||
glClearDepthf(1.f);
|
||||
#else
|
||||
glClearDepth(1.f);
|
||||
#endif
|
||||
|
||||
glClearColor(0.f, 0.5f, 0.5f, 0.f);
|
||||
|
||||
// Enable Z-buffer read and write
|
||||
|
@ -33,9 +42,14 @@ void initialize(sf::Window& window)
|
|||
// Setup a perspective projection
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
static const double pi = 3.141592654;
|
||||
GLdouble extent = std::tan(90.0 * pi / 360.0);
|
||||
glFrustum(-extent, extent, -extent, extent, 1.0, 500.0);
|
||||
static const float pi = 3.141592654f;
|
||||
float extent = std::tan(90.0f * pi / 360.0f);
|
||||
|
||||
#ifdef SFML_OPENGL_ES
|
||||
glFrustumf(-extent, extent, -extent, extent, 1.0f, 500.0f);
|
||||
#else
|
||||
glFrustum(-extent, extent, -extent, extent, 1.0f, 500.0f);
|
||||
#endif
|
||||
|
||||
// Enable position and texture coordinates vertex components
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
@ -177,6 +191,15 @@ int main()
|
|||
// Create a clock for measuring elapsed time
|
||||
sf::Clock clock;
|
||||
|
||||
// Load OpenGL or OpenGL ES entry points using glad
|
||||
sfmlView1.setActive();
|
||||
|
||||
#ifdef SFML_OPENGL_ES
|
||||
gladLoadGLES1(reinterpret_cast<GLADloadfunc>(sf::Context::getFunction));
|
||||
#else
|
||||
gladLoadGL(reinterpret_cast<GLADloadfunc>(sf::Context::getFunction));
|
||||
#endif
|
||||
|
||||
// Initialize our views
|
||||
initialize(sfmlView1);
|
||||
initialize(sfmlView2);
|
||||
|
|
7837
examples/X11/gl.h
Normal file
7837
examples/X11/gl.h
Normal file
File diff suppressed because it is too large
Load diff
|
@ -16,5 +16,5 @@ endif()
|
|||
sfml_add_example(opengl GUI_APP
|
||||
SOURCES ${SRC}
|
||||
BUNDLE_RESOURCES ${RESOURCES}
|
||||
DEPENDS sfml-graphics OpenGL
|
||||
DEPENDS sfml-graphics
|
||||
RESOURCES_DIR resources)
|
||||
|
|
|
@ -3,17 +3,14 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <SFML/OpenGL.hpp>
|
||||
|
||||
#define GLAD_GL_IMPLEMENTATION
|
||||
#include "gl.h"
|
||||
|
||||
#ifdef SFML_SYSTEM_IOS
|
||||
#include <SFML/Main.hpp>
|
||||
#endif
|
||||
|
||||
#ifdef SFML_OPENGL_ES
|
||||
#define glClearDepth glClearDepthf
|
||||
#define glFrustum glFrustumf
|
||||
#endif
|
||||
|
||||
#ifndef GL_SRGB8_ALPHA8
|
||||
#define GL_SRGB8_ALPHA8 0x8C43
|
||||
#endif
|
||||
|
@ -83,10 +80,21 @@ int main()
|
|||
// Make the window the active window for OpenGL calls
|
||||
window.setActive(true);
|
||||
|
||||
// Load OpenGL or OpenGL ES entry points using glad
|
||||
#ifdef SFML_OPENGL_ES
|
||||
gladLoadGLES1(reinterpret_cast<GLADloadfunc>(sf::Context::getFunction));
|
||||
#else
|
||||
gladLoadGL(reinterpret_cast<GLADloadfunc>(sf::Context::getFunction));
|
||||
#endif
|
||||
|
||||
// Enable Z-buffer read and write
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_TRUE);
|
||||
#ifdef SFML_OPENGL_ES
|
||||
glClearDepthf(1.f);
|
||||
#else
|
||||
glClearDepth(1.f);
|
||||
#endif
|
||||
|
||||
// Disable lighting
|
||||
glDisable(GL_LIGHTING);
|
||||
|
@ -98,7 +106,11 @@ int main()
|
|||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
GLfloat ratio = static_cast<float>(window.getSize().x) / window.getSize().y;
|
||||
#ifdef SFML_OPENGL_ES
|
||||
glFrustumf(-ratio, ratio, -1.f, 1.f, 1.f, 500.f);
|
||||
#else
|
||||
glFrustum(-ratio, ratio, -1.f, 1.f, 1.f, 500.f);
|
||||
#endif
|
||||
|
||||
// Bind the texture
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
@ -221,7 +233,7 @@ int main()
|
|||
if (event.type == sf::Event::Resized)
|
||||
{
|
||||
sf::Vector2u textureSize = backgroundTexture.getSize();
|
||||
|
||||
|
||||
// Make the window the active window for OpenGL calls
|
||||
window.setActive(true);
|
||||
|
||||
|
@ -229,11 +241,15 @@ int main()
|
|||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
GLfloat ratio = static_cast<float>(event.size.width) / event.size.height;
|
||||
#ifdef SFML_OPENGL_ES
|
||||
glFrustumf(-ratio, ratio, -1.f, 1.f, 1.f, 500.f);
|
||||
#else
|
||||
glFrustum(-ratio, ratio, -1.f, 1.f, 1.f, 500.f);
|
||||
#endif
|
||||
|
||||
// Make the window no longer the active window for OpenGL calls
|
||||
window.setActive(false);
|
||||
|
||||
|
||||
sf::View view;
|
||||
view.setSize(textureSize.x, textureSize.y);
|
||||
view.setCenter(textureSize.x/2.f, textureSize.y/2.f);
|
||||
|
@ -254,13 +270,13 @@ int main()
|
|||
|
||||
// We get the position of the mouse cursor (or touch), so that we can move the box accordingly
|
||||
sf::Vector2i pos;
|
||||
|
||||
|
||||
#ifdef SFML_SYSTEM_IOS
|
||||
pos = sf::Touch::getPosition(0);
|
||||
#else
|
||||
pos = sf::Mouse::getPosition();
|
||||
#endif
|
||||
|
||||
|
||||
float x = pos.x * 200.f / window.getSize().x - 100.f;
|
||||
float y = -pos.y * 200.f / window.getSize().y + 100.f;
|
||||
|
||||
|
|
7837
examples/opengl/gl.h
Normal file
7837
examples/opengl/gl.h
Normal file
File diff suppressed because it is too large
Load diff
|
@ -7,4 +7,4 @@ set(SRC ${SRCROOT}/Window.cpp)
|
|||
# define the window target
|
||||
sfml_add_example(window GUI_APP
|
||||
SOURCES ${SRC}
|
||||
DEPENDS sfml-window OpenGL)
|
||||
DEPENDS sfml-window)
|
||||
|
|
|
@ -2,17 +2,14 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window.hpp>
|
||||
#include <SFML/OpenGL.hpp>
|
||||
|
||||
#define GLAD_GL_IMPLEMENTATION
|
||||
#include "gl.h"
|
||||
|
||||
#ifdef SFML_SYSTEM_IOS
|
||||
#include <SFML/Main.hpp>
|
||||
#endif
|
||||
|
||||
#ifdef SFML_OPENGL_ES
|
||||
#define glClearDepth glClearDepthf
|
||||
#define glFrustum glFrustumf
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Entry point of application
|
||||
///
|
||||
|
@ -31,8 +28,19 @@ int main()
|
|||
// Make it the active window for OpenGL calls
|
||||
window.setActive();
|
||||
|
||||
// Load OpenGL or OpenGL ES entry points using glad
|
||||
#ifdef SFML_OPENGL_ES
|
||||
gladLoadGLES1(reinterpret_cast<GLADloadfunc>(sf::Context::getFunction));
|
||||
#else
|
||||
gladLoadGL(reinterpret_cast<GLADloadfunc>(sf::Context::getFunction));
|
||||
#endif
|
||||
|
||||
// Set the color and depth clear values
|
||||
#ifdef SFML_OPENGL_ES
|
||||
glClearDepthf(1.f);
|
||||
#else
|
||||
glClearDepth(1.f);
|
||||
#endif
|
||||
glClearColor(0.f, 0.f, 0.f, 1.f);
|
||||
|
||||
// Enable Z-buffer read and write
|
||||
|
@ -50,7 +58,11 @@ int main()
|
|||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
GLfloat ratio = static_cast<float>(window.getSize().x) / window.getSize().y;
|
||||
#ifdef SFML_OPENGL_ES
|
||||
glFrustumf(-ratio, ratio, -1.f, 1.f, 1.f, 500.f);
|
||||
#else
|
||||
glFrustum(-ratio, ratio, -1.f, 1.f, 1.f, 500.f);
|
||||
#endif
|
||||
|
||||
// Define a 3D cube (6 faces made of 2 triangles composed by 3 vertices)
|
||||
GLfloat cube[] =
|
||||
|
@ -134,7 +146,11 @@ int main()
|
|||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
GLfloat ratio = static_cast<float>(event.size.width) / event.size.height;
|
||||
#ifdef SFML_OPENGL_ES
|
||||
glFrustumf(-ratio, ratio, -1.f, 1.f, 1.f, 500.f);
|
||||
#else
|
||||
glFrustum(-ratio, ratio, -1.f, 1.f, 1.f, 500.f);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
7837
examples/window/gl.h
Normal file
7837
examples/window/gl.h
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue