[DEV] update to Web build mode
This commit is contained in:
parent
82e6842c4a
commit
544d9e2e02
@ -588,8 +588,8 @@ bool gale::Context::OS_Draw(bool _displayEveryTime) {
|
||||
m_FpsSystem.tic();
|
||||
}
|
||||
if (m_application != nullptr) {
|
||||
if( true == needRedraw
|
||||
|| true == _displayEveryTime) {
|
||||
if( needRedraw == true
|
||||
|| _displayEveryTime == true) {
|
||||
m_FpsSystem.incrementCounter();
|
||||
// set the curent interface :
|
||||
lockContext();
|
||||
@ -621,7 +621,7 @@ bool gale::Context::OS_Draw(bool _displayEveryTime) {
|
||||
m_FpsFlush.draw();
|
||||
}
|
||||
{
|
||||
// set the curent interface :
|
||||
// set the curent interface:
|
||||
lockContext();
|
||||
// release open GL Context
|
||||
gale::openGL::lock();
|
||||
@ -631,7 +631,7 @@ bool gale::Context::OS_Draw(bool _displayEveryTime) {
|
||||
gale::openGL::unLock();
|
||||
// TODO : m_objectManager.cleanInternalRemoved();
|
||||
m_resourceManager.cleanInternalRemoved();
|
||||
// release the curent interface :
|
||||
// release the curent interface:
|
||||
unLockContext();
|
||||
}
|
||||
gale::openGL::threadHasNoMoreContext();
|
||||
|
227
gale/context/SDL/Context.cpp
Normal file
227
gale/context/SDL/Context.cpp
Normal file
@ -0,0 +1,227 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/tool.hpp>
|
||||
|
||||
#include <gale/debug.hpp>
|
||||
#include <gale/gale.hpp>
|
||||
#include <gale/key/key.hpp>
|
||||
#include <gale/context/commandLine.hpp>
|
||||
#include <gale/resource/Manager.hpp>
|
||||
#include <gale/context/Context.hpp>
|
||||
#include <gale/Dimension.hpp>
|
||||
#include <etk/etk.hpp>
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glut.h>
|
||||
#include <emscripten.h>
|
||||
|
||||
bool hasDisplay = false;
|
||||
//#define DEBUG_SDL_EVENT
|
||||
#ifdef DEBUG_SDL_EVENT
|
||||
#define SDL_DEBUG GALE_DEBUG
|
||||
#define SDL_VERBOSE GALE_VERBOSE
|
||||
#define SDL_INFO GALE_INFO
|
||||
#define SDL_CRITICAL GALE_CRITICAL
|
||||
#else
|
||||
#define SDL_DEBUG GALE_VERBOSE
|
||||
#define SDL_VERBOSE GALE_VERBOSE
|
||||
#define SDL_INFO GALE_VERBOSE
|
||||
#define SDL_CRITICAL GALE_VERBOSE
|
||||
#endif
|
||||
|
||||
#ifdef GALE_BUILD_EGAMI
|
||||
#include <egami/egami.hpp>
|
||||
#endif
|
||||
|
||||
|
||||
class SDLInterface : public gale::Context {
|
||||
private:
|
||||
gale::key::Special m_guiKeyBoardMode;
|
||||
int32_t m_originX;
|
||||
int32_t m_originY;
|
||||
int32_t m_cursorEventX;
|
||||
int32_t m_cursorEventY;
|
||||
int32_t m_currentHeight;
|
||||
int32_t m_currentWidth;
|
||||
bool m_doubleBuffered;
|
||||
bool m_run;
|
||||
//forcing the position
|
||||
bool m_grabAllEvent; //!< grab mode enable...
|
||||
vec2 m_forcePos; //!< position to reset the cursor
|
||||
bool m_positionChangeRequested; //!< the position modifiquation has been requested
|
||||
vec2 m_curentGrabDelta; //!< the position in SDL will arrive by pool
|
||||
bool m_inputIsPressed[MAX_MANAGE_INPUT];
|
||||
std::string m_uniqueWindowsName;
|
||||
enum gale::context::cursor m_currentCursor; //!< select the current cursor to display :
|
||||
char32_t m_lastKeyPressed; //!< The last element key presed...
|
||||
public:
|
||||
SDLInterface(gale::Application* _application, int32_t _argc, const char* _argv[]) :
|
||||
gale::Context(_application, _argc, _argv),
|
||||
m_originX(0),
|
||||
m_originY(0),
|
||||
m_cursorEventX(0),
|
||||
m_cursorEventY(0),
|
||||
m_currentHeight(450),
|
||||
m_currentWidth(600),
|
||||
m_doubleBuffered(0),
|
||||
m_run(false),
|
||||
m_grabAllEvent(false),
|
||||
m_forcePos(0,0),
|
||||
m_positionChangeRequested(false),
|
||||
m_curentGrabDelta(0,0),
|
||||
m_currentCursor(gale::context::cursor::arrow),
|
||||
m_lastKeyPressed(0) {
|
||||
SDL_INFO("SDL:INIT");
|
||||
for (int32_t iii=0; iii<MAX_MANAGE_INPUT; iii++) {
|
||||
m_inputIsPressed[iii] = false;
|
||||
}
|
||||
if (m_doubleBuffered) {
|
||||
//XSync(m_display,0);
|
||||
}
|
||||
OS_Resize(vec2(m_currentWidth, m_currentHeight));
|
||||
|
||||
// Configure the DPI of the screen:
|
||||
{
|
||||
vec2 dpi(0,0);
|
||||
dpi.setX(75);
|
||||
dpi.setY(75);
|
||||
gale::Dimension::setPixelRatio(dpi, gale::distance::inch);
|
||||
GALE_INFO("monitor property : dpi=" << dpi << " px/inch");
|
||||
}
|
||||
m_run = true;
|
||||
}
|
||||
|
||||
~SDLInterface() {
|
||||
//SDL_Quit();
|
||||
}
|
||||
|
||||
int32_t run() {
|
||||
SDL_INFO("RUN");
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
SDL_INFO("RUN 2");
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
SDL_INFO("RUN 3");
|
||||
//glLoadIdentity();
|
||||
SDL_INFO("Draw [START]");
|
||||
OS_Draw(true);
|
||||
SDL_INFO("Draw [STOP]");
|
||||
glutSwapBuffers();
|
||||
//std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
return 0;
|
||||
}
|
||||
/****************************************************************************************/
|
||||
virtual void stop() {
|
||||
SDL_INFO("SDL-API: Stop");
|
||||
m_run = false;
|
||||
}
|
||||
};
|
||||
|
||||
SDLInterface* g_interface = nullptr;
|
||||
|
||||
static void gears_idle() {
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a new window size or exposure.
|
||||
*
|
||||
* @param width the window width
|
||||
* @param height the window height
|
||||
*/
|
||||
static void gears_reshape(int width, int height) {
|
||||
/* Update the projection matrix */
|
||||
//perspective(ProjectionMatrix, 60.0, width / (float)height, 1.0, 1024.0);
|
||||
/* Set the viewport */
|
||||
glViewport(0, 0, (GLint) width, (GLint) height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the gears.
|
||||
*/
|
||||
static void gears_draw() {
|
||||
g_interface->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles special glut events.
|
||||
*
|
||||
* @param special the event to handle.
|
||||
*/
|
||||
static void gears_special(int _special, int _crap, int _morecrap) {
|
||||
switch (_special) {
|
||||
case GLUT_KEY_LEFT:
|
||||
GALE_INFO("GLUT_KEY_LEFT");
|
||||
break;
|
||||
case GLUT_KEY_RIGHT:
|
||||
GALE_INFO("GLUT_KEY_RIGHT");
|
||||
break;
|
||||
case GLUT_KEY_UP:
|
||||
GALE_INFO("GLUT_KEY_UP");
|
||||
break;
|
||||
case GLUT_KEY_DOWN:
|
||||
GALE_INFO("GLUT_KEY_DOWN");
|
||||
break;
|
||||
case GLUT_KEY_F11:
|
||||
glutFullScreen();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Main of the program
|
||||
* @param std IO
|
||||
* @return std IO
|
||||
*/
|
||||
int gale::run(gale::Application* _application, int _argc, const char *_argv[]) {
|
||||
GALE_DEBUG("lklklklklk\n");
|
||||
#ifndef __EMSCRIPTEN__
|
||||
// include GL stuff, to check that we can compile hybrid 2d/GL apps
|
||||
extern void glBegin(int mode);
|
||||
extern void glBindBuffer(int target, int buffer);
|
||||
if (_argc == 9876) {
|
||||
glBegin(0);
|
||||
glBindBuffer(0, 0);
|
||||
}
|
||||
#endif
|
||||
GALE_DEBUG("22222222\n");
|
||||
etk::init(_argc, _argv);
|
||||
GALE_DEBUG("33333333\n");
|
||||
g_interface = new SDLInterface(_application, _argc, _argv);
|
||||
if (g_interface == nullptr) {
|
||||
GALE_CRITICAL("Can not create the SDL interface ... MEMORY allocation error");
|
||||
return -2;
|
||||
}
|
||||
|
||||
/* Initialize the window */
|
||||
glutInit(&_argc, (char**)_argv);
|
||||
glutInitWindowSize(600, 450);
|
||||
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
|
||||
glutCreateWindow("coucou, name to change ...");
|
||||
/* Set up glut callback functions */
|
||||
glutIdleFunc(gears_idle);
|
||||
glutReshapeFunc(gears_reshape);
|
||||
glutDisplayFunc(gears_draw);
|
||||
glutSpecialFunc(gears_special);
|
||||
GALE_DEBUG("7987984654654\n");
|
||||
|
||||
glutMainLoop();
|
||||
|
||||
GALE_DEBUG("444444\n");
|
||||
int32_t retValue = 0; //g_interface->run();
|
||||
|
||||
delete(g_interface);
|
||||
g_interface = nullptr;
|
||||
return retValue;
|
||||
}
|
390
gale/context/SDL/Context_SDL1.cpp
Normal file
390
gale/context/SDL/Context_SDL1.cpp
Normal file
@ -0,0 +1,390 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/tool.hpp>
|
||||
|
||||
#include <gale/debug.hpp>
|
||||
#include <gale/gale.hpp>
|
||||
#include <gale/key/key.hpp>
|
||||
#include <gale/context/commandLine.hpp>
|
||||
#include <gale/resource/Manager.hpp>
|
||||
#include <gale/context/Context.hpp>
|
||||
#include <gale/Dimension.hpp>
|
||||
#include <etk/etk.hpp>
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
#include <SDL/SDL_ttf.h>
|
||||
#include "SDL/SDL_opengl.h"
|
||||
#include <emscripten.h>
|
||||
|
||||
bool hasDisplay = false;
|
||||
//#define DEBUG_SDL_EVENT
|
||||
#ifdef DEBUG_SDL_EVENT
|
||||
#define SDL_DEBUG GALE_DEBUG
|
||||
#define SDL_VERBOSE GALE_VERBOSE
|
||||
#define SDL_INFO GALE_INFO
|
||||
#define SDL_CRITICAL GALE_CRITICAL
|
||||
#else
|
||||
#define SDL_DEBUG GALE_VERBOSE
|
||||
#define SDL_VERBOSE GALE_VERBOSE
|
||||
#define SDL_INFO GALE_VERBOSE
|
||||
#define SDL_CRITICAL GALE_VERBOSE
|
||||
#endif
|
||||
|
||||
#ifdef GALE_BUILD_EGAMI
|
||||
#include <egami/egami.hpp>
|
||||
#endif
|
||||
|
||||
int result = 1;
|
||||
|
||||
static char *TouchFingerTypeToString(int type) {
|
||||
if (type == SDL_FINGERMOTION) return "SDL_FINGERMOTION";
|
||||
if (type == SDL_FINGERDOWN) return "SDL_FINGERDOWN";
|
||||
if (type == SDL_FINGERUP) return "SDL_FINGERUP";
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
int got_down = 0;
|
||||
int got_move = 0;
|
||||
int got_up = 0;
|
||||
|
||||
|
||||
void progress() {
|
||||
if (!got_down) printf("Hold down a finger to generate a touch down event.\n");
|
||||
else if (!got_move) printf("Drag a finger to generate a touch move event.\n");
|
||||
else if (!got_up) printf("Release a finger to generate a touch up event.\n");
|
||||
else
|
||||
{
|
||||
int result = 0;
|
||||
#ifdef REPORT_RESULT
|
||||
REPORT_RESULT();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void loopppp(void* arg) {
|
||||
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch(event.type) {
|
||||
case SDL_FINGERMOTION:
|
||||
case SDL_FINGERDOWN:
|
||||
case SDL_FINGERUP: {
|
||||
SDL_TouchFingerEvent *t = (SDL_TouchFingerEvent*)&event;
|
||||
printf("type: %s, timestamp: %u, touchId: %llu, fingerId: %llu, x: %f, y: %f, dx: %f, dy: %f, pressure: %f\n",
|
||||
TouchFingerTypeToString(event.type), t->timestamp, t->touchId, t->fingerId, t->x, t->y, t->dx, t->dy, t->pressure);
|
||||
|
||||
if (t->timestamp != 0 && t->x >= 0.f && t->x <= 1.f && t->y >= 0.f && t->y <= 1.f && t->pressure >= 0.f && t->pressure <= 1.f) {
|
||||
if (event.type == SDL_FINGERDOWN) { got_down = 1; progress(); }
|
||||
if (event.type == SDL_FINGERMOTION) { got_move = 1; progress(); }
|
||||
if (event.type == SDL_FINGERDOWN) { got_up = 1; progress(); }
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class SDLInterface : public gale::Context {
|
||||
private:
|
||||
gale::key::Special m_guiKeyBoardMode;
|
||||
int32_t m_originX;
|
||||
int32_t m_originY;
|
||||
int32_t m_cursorEventX;
|
||||
int32_t m_cursorEventY;
|
||||
int32_t m_currentHeight;
|
||||
int32_t m_currentWidth;
|
||||
bool m_doubleBuffered;
|
||||
bool m_run;
|
||||
//forcing the position
|
||||
bool m_grabAllEvent; //!< grab mode enable...
|
||||
vec2 m_forcePos; //!< position to reset the cursor
|
||||
bool m_positionChangeRequested; //!< the position modifiquation has been requested
|
||||
vec2 m_curentGrabDelta; //!< the position in SDL will arrive by pool
|
||||
bool m_inputIsPressed[MAX_MANAGE_INPUT];
|
||||
std::string m_uniqueWindowsName;
|
||||
enum gale::context::cursor m_currentCursor; //!< select the current cursor to display :
|
||||
char32_t m_lastKeyPressed; //!< The last element key presed...
|
||||
SDL_Surface* m_screen;
|
||||
public:
|
||||
SDLInterface(gale::Application* _application, int32_t _argc, const char* _argv[]) :
|
||||
gale::Context(_application, _argc, _argv),
|
||||
m_originX(0),
|
||||
m_originY(0),
|
||||
m_cursorEventX(0),
|
||||
m_cursorEventY(0),
|
||||
m_currentHeight(450),
|
||||
m_currentWidth(600),
|
||||
m_doubleBuffered(0),
|
||||
m_run(false),
|
||||
m_grabAllEvent(false),
|
||||
m_forcePos(0,0),
|
||||
m_positionChangeRequested(false),
|
||||
m_curentGrabDelta(0,0),
|
||||
m_currentCursor(gale::context::cursor::arrow),
|
||||
m_lastKeyPressed(0),
|
||||
m_screen(nullptr) {
|
||||
SDL_INFO("SDL:INIT");
|
||||
for (int32_t iii=0; iii<MAX_MANAGE_INPUT; iii++) {
|
||||
m_inputIsPressed[iii] = false;
|
||||
}
|
||||
if (m_doubleBuffered) {
|
||||
//XSync(m_display,0);
|
||||
}
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // *new*
|
||||
m_screen = SDL_SetVideoMode(m_currentWidth, m_currentHeight, 32, SDL_OPENGL/*SDL_HWSURFACE*/);
|
||||
SDL_INFO("SDL:INIT");
|
||||
// Set the OpenGL state after creating the context with SDL_SetVideoMode
|
||||
|
||||
glClearColor( 0, 0, 0, 0 );
|
||||
SDL_INFO("SDL:INIT");
|
||||
glEnable( GL_TEXTURE_2D ); // Needed when we're using the fixed-function pipeline.
|
||||
|
||||
glViewport( 0, 0, 640, 480 );
|
||||
SDL_INFO("SDL:INIT");
|
||||
glMatrixMode( GL_PROJECTION );
|
||||
SDL_INFO("SDL:INIT");
|
||||
glPushMatrix(); // just for testing
|
||||
SDL_INFO("SDL:INIT");
|
||||
glLoadIdentity();
|
||||
SDL_INFO("SDL:INIT");
|
||||
glOrtho( 0, 640, 480, 0, -1000, 1000 );
|
||||
|
||||
SDL_INFO("SDL:INIT");
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
SDL_INFO("SDL:INIT");
|
||||
glLoadIdentity();
|
||||
SDL_INFO("SDL:INIT");
|
||||
OS_Resize(vec2(m_currentWidth, m_currentHeight));
|
||||
|
||||
SDL_INFO("SDL:INIT");
|
||||
// Configure the DPI of the screen:
|
||||
{
|
||||
vec2 dpi(0,0);
|
||||
dpi.setX(75);
|
||||
dpi.setY(75);
|
||||
gale::Dimension::setPixelRatio(dpi, gale::distance::inch);
|
||||
GALE_INFO("monitor property : dpi=" << dpi << " px/inch");
|
||||
}
|
||||
m_run = true;
|
||||
}
|
||||
|
||||
~SDLInterface() {
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
int32_t run() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch(event.type) {
|
||||
case SDL_FINGERMOTION:
|
||||
case SDL_FINGERDOWN:
|
||||
case SDL_FINGERUP: {
|
||||
SDL_TouchFingerEvent *t = (SDL_TouchFingerEvent*)&event;
|
||||
SDL_INFO("type: " << TouchFingerTypeToString(event.type)
|
||||
<< ", timestamp: " << t->timestamp
|
||||
<< ", touchId: " << t->touchId
|
||||
<< ", fingerId: " << t->fingerId
|
||||
<< ", pos=" << vec2(t->x, t->y)
|
||||
<< ", delta Pos=" << vec2(t->dx, t->dy)
|
||||
<< ", pressure: " << t->pressure);
|
||||
if (t->timestamp != 0 && t->x >= 0.f && t->x <= 1.f && t->y >= 0.f && t->y <= 1.f && t->pressure >= 0.f && t->pressure <= 1.f) {
|
||||
if (event.type == SDL_FINGERDOWN) {
|
||||
got_down = 1; progress();
|
||||
}
|
||||
if (event.type == SDL_FINGERMOTION) {
|
||||
got_move = 1; progress();
|
||||
}
|
||||
if (event.type == SDL_FINGERDOWN) {
|
||||
got_up = 1; progress();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (SDL_MUSTLOCK(m_screen)) {
|
||||
SDL_LockSurface(m_screen);
|
||||
}
|
||||
/*
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glLoadIdentity();
|
||||
*/
|
||||
if (true) {
|
||||
for (int yyy = 0; yyy < m_currentWidth; yyy++) {
|
||||
for (int xxx = 0; xxx < m_currentHeight; xxx++) {
|
||||
#ifdef TEST_SDL_LOCK_OPTS
|
||||
// Alpha behaves like in the browser, so write proper opaque pixels.
|
||||
int alpha = 255;
|
||||
#else
|
||||
// To emulate native behavior with blitting to screen, alpha component is ignored. Test that it is so by outputting
|
||||
// data (and testing that it does get discarded)
|
||||
int alpha = (yyy+xxx) % 255;
|
||||
#endif
|
||||
*((Uint32*)m_screen->pixels + yyy * m_currentWidth + xxx) = SDL_MapRGBA(m_screen->format, yyy, xxx, (Uint32)(255.0f * float(yyy)/float(m_currentHeight)), alpha);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (SDL_MUSTLOCK(m_screen)) {
|
||||
SDL_UnlockSurface(m_screen);
|
||||
}
|
||||
SDL_INFO("Draw [START]");
|
||||
OS_Draw(true);
|
||||
SDL_INFO("Draw [STOP]");
|
||||
SDL_Flip(m_screen);
|
||||
|
||||
return 0;
|
||||
|
||||
// main cycle
|
||||
//while(m_run == true) {
|
||||
SDL_Event evt;
|
||||
if ( SDL_PollEvent(&evt) != 0
|
||||
&& evt.type == SDL_QUIT) {
|
||||
m_run = false;
|
||||
return -1;
|
||||
}
|
||||
if(m_run == true) {
|
||||
if ( m_doubleBuffered == true
|
||||
&& hasDisplay == true) {
|
||||
// TODO : SWAP ....
|
||||
}
|
||||
//hasDisplay = OS_Draw(true);
|
||||
//SDL_LockSurface(m_screen);
|
||||
|
||||
if (SDL_MUSTLOCK(m_screen)) {
|
||||
//SDL_LockSurface(m_screen);
|
||||
}
|
||||
if (false) {
|
||||
for (int i = 0; i < 256; i++) {
|
||||
for (int j = 0; j < 256; j++) {
|
||||
#ifdef TEST_SDL_LOCK_OPTS
|
||||
// Alpha behaves like in the browser, so write proper opaque pixels.
|
||||
int alpha = 255;
|
||||
#else
|
||||
// To emulate native behavior with blitting to screen, alpha component is ignored. Test that it is so by outputting
|
||||
// data (and testing that it does get discarded)
|
||||
int alpha = (i+j) % 255;
|
||||
#endif
|
||||
*((Uint32*)m_screen->pixels + i * 256 + j) = SDL_MapRGBA(m_screen->format, i, j, 255-i, alpha);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
OS_Draw(true);
|
||||
}
|
||||
if (SDL_MUSTLOCK(m_screen)) {
|
||||
//SDL_UnlockSurface(m_screen);
|
||||
}
|
||||
SDL_Flip(m_screen);
|
||||
//SDL_UnlockSurface(m_screen);
|
||||
//SDL_Delay(33);
|
||||
}
|
||||
//}
|
||||
/*
|
||||
// main cycle
|
||||
while(m_run == true) {
|
||||
SDL_Event evt;
|
||||
if ( SDL_PollEvent(&evt) != 0
|
||||
&& evt.type == SDL_QUIT) {
|
||||
m_run = false;
|
||||
continue;
|
||||
}
|
||||
if(m_run == true) {
|
||||
if ( m_doubleBuffered == true
|
||||
&& hasDisplay == true) {
|
||||
// TODO : SWAP ....
|
||||
}
|
||||
//hasDisplay = OS_Draw(true);
|
||||
//SDL_LockSurface(m_screen);
|
||||
|
||||
if (SDL_MUSTLOCK(m_screen)) {
|
||||
SDL_LockSurface(m_screen);
|
||||
}
|
||||
for (int i = 0; i < 256; i++) {
|
||||
for (int j = 0; j < 256; j++) {
|
||||
#ifdef TEST_SDL_LOCK_OPTS
|
||||
// Alpha behaves like in the browser, so write proper opaque pixels.
|
||||
int alpha = 255;
|
||||
#else
|
||||
// To emulate native behavior with blitting to screen, alpha component is ignored. Test that it is so by outputting
|
||||
// data (and testing that it does get discarded)
|
||||
int alpha = (i+j) % 255;
|
||||
#endif
|
||||
*((Uint32*)m_screen->pixels + i * 256 + j) = SDL_MapRGBA(m_screen->format, i, j, 255-i, alpha);
|
||||
}
|
||||
}
|
||||
if (SDL_MUSTLOCK(m_screen)) {
|
||||
SDL_UnlockSurface(m_screen);
|
||||
}
|
||||
SDL_Flip(m_screen);
|
||||
//SDL_UnlockSurface(m_screen);
|
||||
SDL_Delay(33);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
/****************************************************************************************/
|
||||
virtual void stop() {
|
||||
SDL_INFO("SDL-API: Stop");
|
||||
m_run = false;
|
||||
}
|
||||
};
|
||||
|
||||
static void loop(void* _arg) {
|
||||
SDLInterface* interface = (SDLInterface*)_arg;
|
||||
if (interface != nullptr) {
|
||||
interface->run();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Main of the program
|
||||
* @param std IO
|
||||
* @return std IO
|
||||
*/
|
||||
int gale::run(gale::Application* _application, int _argc, const char *_argv[]) {
|
||||
printf("lklklklklk\n");
|
||||
#ifndef __EMSCRIPTEN__
|
||||
// include GL stuff, to check that we can compile hybrid 2d/GL apps
|
||||
extern void glBegin(int mode);
|
||||
extern void glBindBuffer(int target, int buffer);
|
||||
if (_argc == 9876) {
|
||||
glBegin(0);
|
||||
glBindBuffer(0, 0);
|
||||
}
|
||||
#endif
|
||||
printf("22222222\n");
|
||||
etk::init(_argc, _argv);
|
||||
printf("33333333\n");
|
||||
SDLInterface* interface = new SDLInterface(_application, _argc, _argv);
|
||||
if (interface == nullptr) {
|
||||
GALE_CRITICAL("Can not create the SDL interface ... MEMORY allocation error");
|
||||
return -2;
|
||||
}
|
||||
printf("444444\n");
|
||||
emscripten_set_main_loop_arg(loop, interface, 0, 0);
|
||||
int32_t retValue = interface->run();
|
||||
printf("55555\n");
|
||||
delete(interface);
|
||||
printf("666666\n");
|
||||
interface = nullptr;
|
||||
return retValue;
|
||||
}
|
349
gale/context/SDL/Context_SDL2.cpp
Normal file
349
gale/context/SDL/Context_SDL2.cpp
Normal file
@ -0,0 +1,349 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/tool.hpp>
|
||||
|
||||
#include <gale/debug.hpp>
|
||||
#include <gale/gale.hpp>
|
||||
#include <gale/key/key.hpp>
|
||||
#include <gale/context/commandLine.hpp>
|
||||
#include <gale/resource/Manager.hpp>
|
||||
#include <gale/context/Context.hpp>
|
||||
#include <gale/Dimension.hpp>
|
||||
#include <etk/etk.hpp>
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
#include <SDL/SDL_ttf.h>
|
||||
//#include <SDL/SDL_opengl.h>
|
||||
#include <SDL/SDL_opengles2.h>
|
||||
#include <emscripten.h>
|
||||
|
||||
bool hasDisplay = false;
|
||||
//#define DEBUG_SDL_EVENT
|
||||
#ifdef DEBUG_SDL_EVENT
|
||||
#define SDL_DEBUG GALE_DEBUG
|
||||
#define SDL_VERBOSE GALE_VERBOSE
|
||||
#define SDL_INFO GALE_INFO
|
||||
#define SDL_CRITICAL GALE_CRITICAL
|
||||
#else
|
||||
#define SDL_DEBUG GALE_VERBOSE
|
||||
#define SDL_VERBOSE GALE_VERBOSE
|
||||
#define SDL_INFO GALE_VERBOSE
|
||||
#define SDL_CRITICAL GALE_VERBOSE
|
||||
#endif
|
||||
|
||||
#ifdef GALE_BUILD_EGAMI
|
||||
#include <egami/egami.hpp>
|
||||
#endif
|
||||
|
||||
int result = 1;
|
||||
|
||||
static char *TouchFingerTypeToString(int type) {
|
||||
if (type == SDL_FINGERMOTION) return "SDL_FINGERMOTION";
|
||||
if (type == SDL_FINGERDOWN) return "SDL_FINGERDOWN";
|
||||
if (type == SDL_FINGERUP) return "SDL_FINGERUP";
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
int got_down = 0;
|
||||
int got_move = 0;
|
||||
int got_up = 0;
|
||||
|
||||
|
||||
void progress() {
|
||||
if (!got_down) printf("Hold down a finger to generate a touch down event.\n");
|
||||
else if (!got_move) printf("Drag a finger to generate a touch move event.\n");
|
||||
else if (!got_up) printf("Release a finger to generate a touch up event.\n");
|
||||
else
|
||||
{
|
||||
int result = 0;
|
||||
#ifdef REPORT_RESULT
|
||||
REPORT_RESULT();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void loopppp(void* arg) {
|
||||
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch(event.type) {
|
||||
case SDL_FINGERMOTION:
|
||||
case SDL_FINGERDOWN:
|
||||
case SDL_FINGERUP: {
|
||||
SDL_TouchFingerEvent *t = (SDL_TouchFingerEvent*)&event;
|
||||
printf("type: %s, timestamp: %u, touchId: %llu, fingerId: %llu, x: %f, y: %f, dx: %f, dy: %f, pressure: %f\n",
|
||||
TouchFingerTypeToString(event.type), t->timestamp, t->touchId, t->fingerId, t->x, t->y, t->dx, t->dy, t->pressure);
|
||||
|
||||
if (t->timestamp != 0 && t->x >= 0.f && t->x <= 1.f && t->y >= 0.f && t->y <= 1.f && t->pressure >= 0.f && t->pressure <= 1.f) {
|
||||
if (event.type == SDL_FINGERDOWN) { got_down = 1; progress(); }
|
||||
if (event.type == SDL_FINGERMOTION) { got_move = 1; progress(); }
|
||||
if (event.type == SDL_FINGERDOWN) { got_up = 1; progress(); }
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class SDLInterface : public gale::Context {
|
||||
private:
|
||||
gale::key::Special m_guiKeyBoardMode;
|
||||
int32_t m_originX;
|
||||
int32_t m_originY;
|
||||
int32_t m_cursorEventX;
|
||||
int32_t m_cursorEventY;
|
||||
int32_t m_currentHeight;
|
||||
int32_t m_currentWidth;
|
||||
bool m_doubleBuffered;
|
||||
bool m_run;
|
||||
//forcing the position
|
||||
bool m_grabAllEvent; //!< grab mode enable...
|
||||
vec2 m_forcePos; //!< position to reset the cursor
|
||||
bool m_positionChangeRequested; //!< the position modifiquation has been requested
|
||||
vec2 m_curentGrabDelta; //!< the position in SDL will arrive by pool
|
||||
bool m_inputIsPressed[MAX_MANAGE_INPUT];
|
||||
std::string m_uniqueWindowsName;
|
||||
enum gale::context::cursor m_currentCursor; //!< select the current cursor to display :
|
||||
char32_t m_lastKeyPressed; //!< The last element key presed...
|
||||
SDL_Window* m_screen;
|
||||
//SDL_Surface* m_screen;
|
||||
SDL_GLContext m_context;
|
||||
public:
|
||||
SDLInterface(gale::Application* _application, int32_t _argc, const char* _argv[]) :
|
||||
gale::Context(_application, _argc, _argv),
|
||||
m_originX(0),
|
||||
m_originY(0),
|
||||
m_cursorEventX(0),
|
||||
m_cursorEventY(0),
|
||||
m_currentHeight(450),
|
||||
m_currentWidth(600),
|
||||
m_doubleBuffered(0),
|
||||
m_run(false),
|
||||
m_grabAllEvent(false),
|
||||
m_forcePos(0,0),
|
||||
m_positionChangeRequested(false),
|
||||
m_curentGrabDelta(0,0),
|
||||
m_currentCursor(gale::context::cursor::arrow),
|
||||
m_lastKeyPressed(0),
|
||||
m_screen(nullptr) {
|
||||
SDL_INFO("SDL:INIT");
|
||||
for (int32_t iii=0; iii<MAX_MANAGE_INPUT; iii++) {
|
||||
m_inputIsPressed[iii] = false;
|
||||
}
|
||||
if (m_doubleBuffered) {
|
||||
//XSync(m_display,0);
|
||||
}
|
||||
SDL_INFO("SDL:INIT");
|
||||
if ( SDL_Init(SDL_INIT_VIDEO) != 0 ) {
|
||||
printf("Unable to initialize SDL: %s\n", SDL_GetError());
|
||||
exit(-1);
|
||||
}
|
||||
SDL_INFO("SDL:INIT");
|
||||
|
||||
m_screen = SDL_CreateWindow("sdl_gl_read", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, m_currentWidth, m_currentHeight, SDL_WINDOW_OPENGL);
|
||||
|
||||
SDL_INFO("SDL:INIT");
|
||||
if (!m_screen) {
|
||||
printf("Unable to create window: %s\n", SDL_GetError());
|
||||
exit(-1);
|
||||
}
|
||||
SDL_INFO("SDL:INIT");
|
||||
m_context = SDL_GL_CreateContext(m_screen);
|
||||
SDL_INFO("SDL:INIT");
|
||||
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // *new*
|
||||
/*
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
m_screen = SDL_SetVideoMode(m_currentWidth, m_currentHeight, 32, SDL_OPENGL/*SDL_HWSURFACE* /);
|
||||
*/
|
||||
SDL_INFO("SDL:INIT");
|
||||
OS_Resize(vec2(m_currentWidth, m_currentHeight));
|
||||
|
||||
// Configure the DPI of the screen:
|
||||
{
|
||||
vec2 dpi(0,0);
|
||||
dpi.setX(75);
|
||||
dpi.setY(75);
|
||||
gale::Dimension::setPixelRatio(dpi, gale::distance::inch);
|
||||
GALE_INFO("monitor property : dpi=" << dpi << " px/inch");
|
||||
}
|
||||
m_run = true;
|
||||
}
|
||||
|
||||
~SDLInterface() {
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
int32_t run() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch(event.type) {
|
||||
case SDL_FINGERMOTION:
|
||||
case SDL_FINGERDOWN:
|
||||
case SDL_FINGERUP: {
|
||||
SDL_TouchFingerEvent *t = (SDL_TouchFingerEvent*)&event;
|
||||
SDL_INFO("type: " << TouchFingerTypeToString(event.type)
|
||||
<< ", timestamp: " << t->timestamp
|
||||
<< ", touchId: " << t->touchId
|
||||
<< ", fingerId: " << t->fingerId
|
||||
<< ", pos=" << vec2(t->x, t->y)
|
||||
<< ", delta Pos=" << vec2(t->dx, t->dy)
|
||||
<< ", pressure: " << t->pressure);
|
||||
if (t->timestamp != 0 && t->x >= 0.f && t->x <= 1.f && t->y >= 0.f && t->y <= 1.f && t->pressure >= 0.f && t->pressure <= 1.f) {
|
||||
if (event.type == SDL_FINGERDOWN) {
|
||||
got_down = 1; progress();
|
||||
}
|
||||
if (event.type == SDL_FINGERMOTION) {
|
||||
got_move = 1; progress();
|
||||
}
|
||||
if (event.type == SDL_FINGERDOWN) {
|
||||
got_up = 1; progress();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
if (SDL_MUSTLOCK(m_screen)) {
|
||||
SDL_LockSurface(m_screen);
|
||||
}
|
||||
*/
|
||||
/*
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glLoadIdentity();
|
||||
*/
|
||||
/*
|
||||
if (true) {
|
||||
for (int yyy = 0; yyy < m_currentWidth; yyy++) {
|
||||
for (int xxx = 0; xxx < m_currentHeight; xxx++) {
|
||||
#ifdef TEST_SDL_LOCK_OPTS
|
||||
// Alpha behaves like in the browser, so write proper opaque pixels.
|
||||
int alpha = 255;
|
||||
#else
|
||||
// To emulate native behavior with blitting to screen, alpha component is ignored. Test that it is so by outputting
|
||||
// data (and testing that it does get discarded)
|
||||
int alpha = (yyy+xxx) % 255;
|
||||
#endif
|
||||
*((Uint32*)m_screen->pixels + yyy * m_currentWidth + xxx) = SDL_MapRGBA(m_screen->format, yyy, xxx, (Uint32)(255.0f * float(yyy)/float(m_currentHeight)), alpha);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (SDL_MUSTLOCK(m_screen)) {
|
||||
SDL_UnlockSurface(m_screen);
|
||||
}
|
||||
*/
|
||||
SDL_INFO("Draw [START]");
|
||||
OS_Draw(true);
|
||||
SDL_INFO("Draw [STOP]");
|
||||
//SDL_Flip(m_screen);
|
||||
|
||||
return 0;
|
||||
|
||||
/*
|
||||
// main cycle
|
||||
while(m_run == true) {
|
||||
SDL_Event evt;
|
||||
if ( SDL_PollEvent(&evt) != 0
|
||||
&& evt.type == SDL_QUIT) {
|
||||
m_run = false;
|
||||
continue;
|
||||
}
|
||||
if(m_run == true) {
|
||||
if ( m_doubleBuffered == true
|
||||
&& hasDisplay == true) {
|
||||
// TODO : SWAP ....
|
||||
}
|
||||
//hasDisplay = OS_Draw(true);
|
||||
//SDL_LockSurface(m_screen);
|
||||
|
||||
if (SDL_MUSTLOCK(m_screen)) {
|
||||
SDL_LockSurface(m_screen);
|
||||
}
|
||||
for (int i = 0; i < 256; i++) {
|
||||
for (int j = 0; j < 256; j++) {
|
||||
#ifdef TEST_SDL_LOCK_OPTS
|
||||
// Alpha behaves like in the browser, so write proper opaque pixels.
|
||||
int alpha = 255;
|
||||
#else
|
||||
// To emulate native behavior with blitting to screen, alpha component is ignored. Test that it is so by outputting
|
||||
// data (and testing that it does get discarded)
|
||||
int alpha = (i+j) % 255;
|
||||
#endif
|
||||
*((Uint32*)m_screen->pixels + i * 256 + j) = SDL_MapRGBA(m_screen->format, i, j, 255-i, alpha);
|
||||
}
|
||||
}
|
||||
if (SDL_MUSTLOCK(m_screen)) {
|
||||
SDL_UnlockSurface(m_screen);
|
||||
}
|
||||
SDL_Flip(m_screen);
|
||||
//SDL_UnlockSurface(m_screen);
|
||||
SDL_Delay(33);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
/****************************************************************************************/
|
||||
virtual void stop() {
|
||||
SDL_INFO("SDL-API: Stop");
|
||||
m_run = false;
|
||||
}
|
||||
};
|
||||
|
||||
static void loop(void* _arg) {
|
||||
SDLInterface* interface = (SDLInterface*)_arg;
|
||||
if (interface != nullptr) {
|
||||
interface->run();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Main of the program
|
||||
* @param std IO
|
||||
* @return std IO
|
||||
*/
|
||||
int gale::run(gale::Application* _application, int _argc, const char *_argv[]) {
|
||||
printf("lklklklklk\n");
|
||||
#ifndef __EMSCRIPTEN__
|
||||
// include GL stuff, to check that we can compile hybrid 2d/GL apps
|
||||
extern void glBegin(int mode);
|
||||
extern void glBindBuffer(int target, int buffer);
|
||||
if (_argc == 9876) {
|
||||
glBegin(0);
|
||||
glBindBuffer(0, 0);
|
||||
}
|
||||
#endif
|
||||
printf("22222222\n");
|
||||
etk::init(_argc, _argv);
|
||||
printf("33333333\n");
|
||||
SDLInterface* interface = new SDLInterface(_application, _argc, _argv);
|
||||
if (interface == nullptr) {
|
||||
GALE_CRITICAL("Can not create the SDL interface ... MEMORY allocation error");
|
||||
return -2;
|
||||
}
|
||||
printf("444444\n");
|
||||
emscripten_set_main_loop_arg(loop, interface, 0, 0);
|
||||
int32_t retValue = interface->run();
|
||||
printf("55555\n");
|
||||
delete(interface);
|
||||
printf("666666\n");
|
||||
interface = nullptr;
|
||||
return retValue;
|
||||
}
|
@ -24,9 +24,18 @@
|
||||
|
||||
|
||||
#if defined(__TARGET_OS__Linux)
|
||||
#include <GL/glx.h>
|
||||
#if defined(__TARGET_OS__Web)
|
||||
#include <X11/Xlibint.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <gale/renderer/openGL/openGL.hpp>
|
||||
#include <gale/renderer/openGL/openGL-include.hpp>
|
||||
#include <GL/glext.h>
|
||||
#include <GL/glfw.h>
|
||||
#else
|
||||
#include <GL/glx.h>
|
||||
#endif
|
||||
#elif defined(__TARGET_OS__MacOs)
|
||||
#include <OpenGL/glx.h>
|
||||
#include <OpenGL/glx.h>
|
||||
#endif
|
||||
|
||||
#include <X11/Xatom.h>
|
||||
@ -50,26 +59,28 @@ bool hasDisplay = false;
|
||||
#define X11_CRITICAL GALE_VERBOSE
|
||||
#endif
|
||||
|
||||
// attributes for a single buffered visual in RGBA format with at least 4 bits per color and a 16 bit depth buffer
|
||||
static int attrListSgl[] = {
|
||||
GLX_RGBA,
|
||||
GLX_RED_SIZE, 4,
|
||||
GLX_GREEN_SIZE, 4,
|
||||
GLX_BLUE_SIZE, 4,
|
||||
GLX_DEPTH_SIZE, 16,
|
||||
None
|
||||
};
|
||||
|
||||
// attributes for a double buffered visual in RGBA format with at least 4 bits per color and a 16 bit depth buffer
|
||||
static int attrListDbl[] = {
|
||||
GLX_RGBA,
|
||||
GLX_DOUBLEBUFFER,
|
||||
GLX_RED_SIZE, 4,
|
||||
GLX_GREEN_SIZE, 4,
|
||||
GLX_BLUE_SIZE, 4,
|
||||
GLX_DEPTH_SIZE, 16,
|
||||
None
|
||||
};
|
||||
#if !defined(__TARGET_OS__Web)
|
||||
// attributes for a single buffered visual in RGBA format with at least 4 bits per color and a 16 bit depth buffer
|
||||
static int attrListSgl[] = {
|
||||
GLX_RGBA,
|
||||
GLX_RED_SIZE, 4,
|
||||
GLX_GREEN_SIZE, 4,
|
||||
GLX_BLUE_SIZE, 4,
|
||||
GLX_DEPTH_SIZE, 16,
|
||||
None
|
||||
};
|
||||
|
||||
// attributes for a double buffered visual in RGBA format with at least 4 bits per color and a 16 bit depth buffer
|
||||
static int attrListDbl[] = {
|
||||
GLX_RGBA,
|
||||
GLX_DOUBLEBUFFER,
|
||||
GLX_RED_SIZE, 4,
|
||||
GLX_GREEN_SIZE, 4,
|
||||
GLX_BLUE_SIZE, 4,
|
||||
GLX_DEPTH_SIZE, 16,
|
||||
None
|
||||
};
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
typedef struct Hints {
|
||||
@ -102,7 +113,9 @@ class X11Interface : public gale::Context {
|
||||
int32_t m_cursorEventY;
|
||||
int32_t m_currentHeight;
|
||||
int32_t m_currentWidth;
|
||||
XVisualInfo* m_visual;
|
||||
#if !defined(__TARGET_OS__Web)
|
||||
XVisualInfo* m_visual;
|
||||
#endif
|
||||
bool m_doubleBuffered;
|
||||
bool m_run;
|
||||
//forcing the position
|
||||
@ -136,7 +149,9 @@ class X11Interface : public gale::Context {
|
||||
m_cursorEventY(0),
|
||||
m_currentHeight(0),
|
||||
m_currentWidth(0),
|
||||
m_visual(nullptr),
|
||||
#if !defined(__TARGET_OS__Web)
|
||||
m_visual(nullptr),
|
||||
#endif
|
||||
m_doubleBuffered(0),
|
||||
m_run(false),
|
||||
m_grabAllEvent(false),
|
||||
@ -160,7 +175,11 @@ class X11Interface : public gale::Context {
|
||||
m_inputIsPressed[iii] = false;
|
||||
}
|
||||
if (m_doubleBuffered) {
|
||||
glXSwapBuffers(m_display, m_WindowHandle);
|
||||
#if defined(__TARGET_OS__Web)
|
||||
glfwSwapBuffers();
|
||||
#else
|
||||
glXSwapBuffers(m_display, m_WindowHandle);
|
||||
#endif
|
||||
XSync(m_display,0);
|
||||
}
|
||||
createX11Context();
|
||||
@ -766,7 +785,11 @@ class X11Interface : public gale::Context {
|
||||
}
|
||||
if(m_run == true) {
|
||||
if (m_doubleBuffered && hasDisplay) {
|
||||
glXSwapBuffers(m_display, m_WindowHandle);
|
||||
#if defined(__TARGET_OS__Web)
|
||||
glfwSwapBuffers();
|
||||
#else
|
||||
glXSwapBuffers(m_display, m_WindowHandle);
|
||||
#endif
|
||||
XSync(m_display,0);
|
||||
}
|
||||
// draw after switch the previous windows ...
|
||||
@ -1033,24 +1056,36 @@ class X11Interface : public gale::Context {
|
||||
gale::Dimension::setPixelRatio(vec2((float)DisplayWidth(m_display, Xscreen)/(float)DisplayWidthMM(m_display, Xscreen),
|
||||
(float)DisplayHeight(m_display, Xscreen)/(float)DisplayHeightMM(m_display, Xscreen)),
|
||||
gale::distance::millimeter);
|
||||
// get an appropriate visual
|
||||
m_visual = glXChooseVisual(m_display, Xscreen, attrListDbl);
|
||||
if (m_visual == nullptr) {
|
||||
m_visual = glXChooseVisual(m_display, Xscreen, attrListSgl);
|
||||
#if !defined(__TARGET_OS__Web)
|
||||
// get an appropriate visual
|
||||
m_visual = glXChooseVisual(m_display, Xscreen, attrListDbl);
|
||||
if (m_visual == nullptr) {
|
||||
m_visual = glXChooseVisual(m_display, Xscreen, attrListSgl);
|
||||
m_doubleBuffered = false;
|
||||
GALE_INFO("GL-X singlebuffered rendering will be used, no doublebuffering available");
|
||||
} else {
|
||||
m_doubleBuffered = true;
|
||||
GALE_INFO("GL-X doublebuffered rendering available");
|
||||
}
|
||||
#else
|
||||
m_doubleBuffered = false;
|
||||
GALE_INFO("GL-X singlebuffered rendering will be used, no doublebuffering available");
|
||||
} else {
|
||||
m_doubleBuffered = true;
|
||||
GALE_INFO("GL-X doublebuffered rendering available");
|
||||
}
|
||||
#endif
|
||||
{
|
||||
int32_t glxMajor, glxMinor;
|
||||
glXQueryVersion(m_display, &glxMajor, &glxMinor);
|
||||
#if defined(__TARGET_OS__Web)
|
||||
int32_t glxRev;
|
||||
glfwGetVersion(&glxMajor, &glxMinor, &glxRev);
|
||||
#else
|
||||
glXQueryVersion(m_display, &glxMajor, &glxMinor);
|
||||
#endif
|
||||
GALE_INFO("GLX-Version " << glxMajor << "." << glxMinor);
|
||||
}
|
||||
// Create a colormap - only needed on some X clients, eg. IRIX
|
||||
Window Xroot = RootWindow(m_display, Xscreen);
|
||||
attr.colormap = XCreateColormap(m_display, Xroot, m_visual->visual, AllocNone);
|
||||
#if !defined(__TARGET_OS__Web)
|
||||
attr.colormap = XCreateColormap(m_display, Xroot, m_visual->visual, AllocNone);
|
||||
#endif
|
||||
|
||||
attr.border_pixel = 0;
|
||||
attr.event_mask = StructureNotifyMask
|
||||
@ -1086,9 +1121,17 @@ class X11Interface : public gale::Context {
|
||||
Xroot,
|
||||
x, y, tmp_width, tmp_height,
|
||||
1,
|
||||
m_visual->depth,
|
||||
#if defined(__TARGET_OS__Web)
|
||||
0,
|
||||
#else
|
||||
m_visual->depth,
|
||||
#endif
|
||||
InputOutput,
|
||||
m_visual->visual,
|
||||
#if defined(__TARGET_OS__Web)
|
||||
0,
|
||||
#else
|
||||
m_visual->visual,
|
||||
#endif
|
||||
attr_mask, &attr);
|
||||
|
||||
if(!m_WindowHandle) {
|
||||
@ -1161,7 +1204,8 @@ class X11Interface : public gale::Context {
|
||||
}
|
||||
/****************************************************************************************/
|
||||
void setIcon(const std::string& _inputFile) {
|
||||
#ifdef GALE_BUILD_EGAMI
|
||||
#if defined(GALE_BUILD_EGAMI) \
|
||||
&& !defined(__TARGET_OS__Web)
|
||||
egami::Image dataImage = egami::load(_inputFile);
|
||||
// load data
|
||||
if (dataImage.exist() == false) {
|
||||
@ -1318,7 +1362,11 @@ class X11Interface : public gale::Context {
|
||||
GALE_ERROR("Can not set the vertical synchronisation status" << _sync << " (1)");
|
||||
return;
|
||||
} else {
|
||||
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALPROC)glXGetProcAddress( (const GLubyte *)"wglSwapIntervalEXT" );
|
||||
#if !defined(__TARGET_OS__Web)
|
||||
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALPROC)glXGetProcAddress( (const GLubyte *)"wglSwapIntervalEXT" );
|
||||
#else
|
||||
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALPROC)glfwGetProcAddress( (const char *)"wglSwapIntervalEXT" );
|
||||
#endif
|
||||
if(wglSwapIntervalEXT) {
|
||||
wglSwapIntervalEXT(_sync);
|
||||
} else {
|
||||
@ -1329,15 +1377,27 @@ class X11Interface : public gale::Context {
|
||||
/****************************************************************************************/
|
||||
bool createOGlContext() {
|
||||
X11_INFO("X11:CreateOGlContext");
|
||||
/* create a GLX context */
|
||||
GLXContext RenderContext = glXCreateContext(m_display, m_visual, 0, GL_TRUE);
|
||||
/* connect the glx-context to the window */
|
||||
glXMakeCurrent(m_display, m_WindowHandle, RenderContext);
|
||||
if (glXIsDirect(m_display, RenderContext)) {
|
||||
GALE_INFO("XF86 DRI enabled\n");
|
||||
} else {
|
||||
GALE_INFO("XF86 DRI NOT available\n");
|
||||
}
|
||||
#if defined(__TARGET_OS__Web)
|
||||
/* create a GLX context */
|
||||
GContext RenderContext = wglCreateContext(m_display, 0, GL_TRUE);
|
||||
/* connect the glx-context to the window */
|
||||
wglMakeCurrent(m_display, m_WindowHandle, RenderContext);
|
||||
if (glwIsDirect(m_display, RenderContext)) {
|
||||
GALE_INFO("XF86 DRI enabled\n");
|
||||
} else {
|
||||
GALE_INFO("XF86 DRI NOT available\n");
|
||||
}
|
||||
#else
|
||||
/* create a GLX context */
|
||||
GLXContext RenderContext = glXCreateContext(m_display, m_visual, 0, GL_TRUE);
|
||||
/* connect the glx-context to the window */
|
||||
glXMakeCurrent(m_display, m_WindowHandle, RenderContext);
|
||||
if (glXIsDirect(m_display, RenderContext)) {
|
||||
GALE_INFO("XF86 DRI enabled\n");
|
||||
} else {
|
||||
GALE_INFO("XF86 DRI NOT available\n");
|
||||
}
|
||||
#endif
|
||||
// enable vertical synchronisation : (some computer has synchronisation disable)
|
||||
setVSync(true);
|
||||
return true;
|
||||
|
@ -28,12 +28,12 @@ static void checkGlError(const char* _op, int32_t _localLine) {
|
||||
#endif
|
||||
}
|
||||
|
||||
#define OPENGL_ERROR(data) do { } while (false)
|
||||
//#define OPENGL_ERROR(data) GALE_ERROR(data)
|
||||
#define OPENGL_WARNING(data) do { } while (false)
|
||||
//#define OPENGL_WARNING(data) GALE_WARNING(data)
|
||||
#define OPENGL_INFO(data) do { } while (false)
|
||||
//#define OPENGL_INFO(data) GALE_INFO(data)
|
||||
//#define OPENGL_ERROR(data) do { } while (false)
|
||||
#define OPENGL_ERROR(data) GALE_ERROR(data)
|
||||
//#define OPENGL_WARNING(data) do { } while (false)
|
||||
#define OPENGL_WARNING(data) GALE_WARNING(data)
|
||||
//#define OPENGL_INFO(data) do { } while (false)
|
||||
#define OPENGL_INFO(data) GALE_INFO(data)
|
||||
|
||||
|
||||
|
||||
@ -207,6 +207,7 @@ void gale::openGL::setViewPort(const ivec2& _start, const ivec2& _stop) {
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
OPENGL_INFO("setViewport " << _start << " " << _stop);
|
||||
glViewport(_start.x(), _start.y(), _stop.x(), _stop.y());
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
}
|
||||
@ -217,6 +218,7 @@ void gale::openGL::setViewPort(const vec2& _start, const vec2& _stop) {
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
OPENGL_INFO("setViewport " << _start << " " << _stop);
|
||||
glViewport(_start.x(), _start.y(), _stop.x(), _stop.y());
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
}
|
||||
@ -635,7 +637,7 @@ void gale::openGL::drawElements8(enum renderMode _mode, const std::vector<uint8_
|
||||
}
|
||||
|
||||
void gale::openGL::useProgram(int32_t _id) {
|
||||
//GALE_DEBUG("USE prog : " << _id);
|
||||
GALE_DEBUG("USE prog : " << _id);
|
||||
#if 1
|
||||
// note : In normal openGL case, the system might call with the program ID and at the end with 0,
|
||||
// here, we wrap this use to prevent over call of glUseProgram == > then we set -1 when the
|
||||
|
@ -361,10 +361,11 @@ void gale::resource::Program::reload() {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void gale::resource::Program::sendAttribute(int32_t _idElem,
|
||||
int32_t _nbElement,
|
||||
const void* _pointer,
|
||||
int32_t _jumpBetweenSample) {
|
||||
void gale::resource::Program::sendAttributePointer(int32_t _idElem,
|
||||
const ememory::SharedPtr<gale::resource::VirtualBufferObject>& _vbo,
|
||||
int32_t _index,
|
||||
int32_t _jumpBetweenSample,
|
||||
int32_t _offset) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
if (m_exist == false) {
|
||||
return;
|
||||
@ -377,34 +378,6 @@ void gale::resource::Program::sendAttribute(int32_t _idElem,
|
||||
if (m_elementList[_idElem].m_isLinked == false) {
|
||||
return;
|
||||
}
|
||||
//GALE_ERROR("[" << m_elementList[_idElem].m_name << "] send " << _nbElement << " element");
|
||||
glVertexAttribPointer(m_elementList[_idElem].m_elementId, // attribute ID of openGL
|
||||
_nbElement, // number of elements per vertex, here (r,g,b,a)
|
||||
GL_FLOAT, // the type of each element
|
||||
GL_FALSE, // take our values as-is
|
||||
_jumpBetweenSample, // no extra data between each position
|
||||
_pointer); // Pointer on the buffer
|
||||
checkGlError("glVertexAttribPointer", __LINE__, _idElem);
|
||||
glEnableVertexAttribArray(m_elementList[_idElem].m_elementId);
|
||||
checkGlError("glEnableVertexAttribArray", __LINE__, _idElem);
|
||||
}
|
||||
|
||||
void gale::resource::Program::sendAttributePointer(int32_t _idElem,
|
||||
const ememory::SharedPtr<gale::resource::VirtualBufferObject>& _vbo,
|
||||
int32_t _index,
|
||||
int32_t _jumpBetweenSample,
|
||||
int32_t _offset) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
if (m_exist == false) {
|
||||
return;
|
||||
}
|
||||
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
|
||||
GALE_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
|
||||
return;
|
||||
}
|
||||
if (false == m_elementList[_idElem].m_isLinked) {
|
||||
return;
|
||||
}
|
||||
// check error of the VBO goog enought ...
|
||||
if (_vbo->getElementSize(_index) <= 0) {
|
||||
GALE_ERROR("Can not bind a VBO Buffer with an element size of : " << _vbo->getElementSize(_index) << " named=" << _vbo->getName());
|
||||
@ -436,7 +409,8 @@ void gale::resource::Program::uniformMatrix(int32_t _idElem, const mat4& _matrix
|
||||
if (m_exist == false) {
|
||||
return;
|
||||
}
|
||||
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
|
||||
if ( _idElem < 0
|
||||
|| (size_t)_idElem > m_elementList.size()) {
|
||||
GALE_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
|
||||
return;
|
||||
}
|
||||
@ -445,7 +419,7 @@ void gale::resource::Program::uniformMatrix(int32_t _idElem, const mat4& _matrix
|
||||
}
|
||||
//GALE_ERROR("[" << m_elementList[_idElem].m_name << "] send 1 matrix");
|
||||
// note : Android des not supported the transposition of the matrix, then we will done it oursef:
|
||||
if (true == _transpose) {
|
||||
if (_transpose == true) {
|
||||
mat4 tmp = _matrix;
|
||||
tmp.transpose();
|
||||
glUniformMatrix4fv(m_elementList[_idElem].m_elementId, 1, GL_FALSE, tmp.m_mat);
|
||||
@ -791,6 +765,7 @@ void gale::resource::Program::uniform4iv(int32_t _idElem, int32_t _nbElement, co
|
||||
|
||||
|
||||
void gale::resource::Program::use() {
|
||||
GALE_WARNING("Will use program : " << m_program);
|
||||
#ifdef PROGRAM_DISPLAY_SPEED
|
||||
g_startTime = gale::getTime();
|
||||
#endif
|
||||
@ -856,7 +831,7 @@ void gale::resource::Program::setTexture1(int32_t _idElem, int64_t _textureOpenG
|
||||
|
||||
|
||||
void gale::resource::Program::unUse() {
|
||||
//GALE_WARNING("Will use program : " << m_program);
|
||||
GALE_WARNING("Will UN-use program : " << m_program);
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
if (m_exist == false) {
|
||||
return;
|
||||
|
@ -83,31 +83,41 @@ namespace gale {
|
||||
/**
|
||||
* @brief Send attribute table to the spefified ID attribure (not send if does not really exist in the openGL program).
|
||||
* @param[in] _idElem Id of the Attribute that might be sended.
|
||||
* @param[in] _nbElement Specifies the number of elements that are to be modified.
|
||||
* @param[in] _pointer Pointer on the data that might be sended.
|
||||
* @param[in] _vbo Reference on the buffer to send.
|
||||
* @param[in] _index Reference on the buffer to send.
|
||||
* @param[in] _jumpBetweenSample Number of byte to jump between 2 vertex (this permit to enterlace informations)
|
||||
* @param[in] _offset offset of start the elements send.
|
||||
*/
|
||||
void sendAttribute(int32_t _idElem,
|
||||
int32_t _nbElement,
|
||||
const void* _pointer,
|
||||
int32_t _jumpBetweenSample=0);
|
||||
void sendAttributePointer(int32_t _idElem,
|
||||
const ememory::SharedPtr<gale::resource::VirtualBufferObject>& _vbo,
|
||||
int32_t _index,
|
||||
int32_t _jumpBetweenSample=0,
|
||||
int32_t _offset=0);
|
||||
inline void sendAttribute(int32_t _idElem, const std::vector<vec2>& _data) {
|
||||
sendAttribute(_idElem, 2/*u,v / x,y*/, &_data[0]);
|
||||
}
|
||||
inline void sendAttribute(int32_t _idElem, const std::vector<vec3>& _data) {
|
||||
sendAttribute(_idElem, 3/*x,y,z,unused*/, &_data[0], 4*sizeof(btScalar));
|
||||
}
|
||||
inline void sendAttribute(int32_t _idElem, const std::vector<etk::Color<float>>& _data) {
|
||||
sendAttribute(_idElem, 4/*r,g,b,a*/, &_data[0]);
|
||||
}
|
||||
inline void sendAttribute(int32_t _idElem, const std::vector<float>& _data) {
|
||||
sendAttribute(_idElem, 1, &_data[0]);
|
||||
}
|
||||
#ifndef THIS_IS_DEPRECATED_TO_REMOVE
|
||||
/**
|
||||
* @brief Send attribute table to the spefified ID attribure (not send if does not really exist in the openGL program).
|
||||
* @param[in] _idElem Id of the Attribute that might be sended.
|
||||
* @param[in] _nbElement Specifies the number of elements that are to be modified.
|
||||
* @param[in] _pointer Pointer on the data that might be sended.
|
||||
* @param[in] _jumpBetweenSample Number of byte to jump between 2 vertex (this permit to enterlace informations)
|
||||
*/
|
||||
void sendAttribute(int32_t _idElem,
|
||||
int32_t _nbElement,
|
||||
const void* _pointer,
|
||||
int32_t _jumpBetweenSample=0);
|
||||
inline void sendAttribute(int32_t _idElem, const std::vector<vec2>& _data) {
|
||||
sendAttribute(_idElem, 2/*u,v / x,y*/, &_data[0]);
|
||||
}
|
||||
inline void sendAttribute(int32_t _idElem, const std::vector<vec3>& _data) {
|
||||
sendAttribute(_idElem, 3/*x,y,z,unused*/, &_data[0], 4*sizeof(btScalar));
|
||||
}
|
||||
inline void sendAttribute(int32_t _idElem, const std::vector<etk::Color<float>>& _data) {
|
||||
sendAttribute(_idElem, 4/*r,g,b,a*/, &_data[0]);
|
||||
}
|
||||
inline void sendAttribute(int32_t _idElem, const std::vector<float>& _data) {
|
||||
sendAttribute(_idElem, 1, &_data[0]);
|
||||
}
|
||||
#endif
|
||||
/**
|
||||
* @brief User request an Uniform on this program.
|
||||
* @note uniform value is availlable for all the fragment shader in the program (only one value for all)
|
||||
|
@ -19,6 +19,21 @@ void gale::resource::VirtualBufferObject::init(int32_t _number) {
|
||||
GALE_DEBUG("OGL : load VBO count=\"" << _number << "\"");
|
||||
}
|
||||
|
||||
void gale::resource::VirtualBufferObject::clear() {
|
||||
for (auto &it : m_vbo) {
|
||||
it = 0;
|
||||
}
|
||||
for (auto &it : m_vboUsed) {
|
||||
it = false;
|
||||
}
|
||||
for (auto &it : m_buffer) {
|
||||
it.clear();
|
||||
}
|
||||
for (auto &it : m_vboSizeDataOffset) {
|
||||
it = -1;
|
||||
}
|
||||
}
|
||||
|
||||
gale::resource::VirtualBufferObject::VirtualBufferObject() :
|
||||
m_exist(false) {
|
||||
addResourceType("gale::VirtualBufferObject");
|
||||
|
@ -38,6 +38,10 @@ namespace gale {
|
||||
*/
|
||||
virtual ~VirtualBufferObject();
|
||||
public:
|
||||
/**
|
||||
* @brief clear buffers
|
||||
*/
|
||||
void clear();
|
||||
/**
|
||||
* @brief get the real openGL ID.
|
||||
* @return the Ogl id reference of this VBO.
|
||||
|
@ -61,7 +61,9 @@ def configure(target, my_module):
|
||||
'gale/context/cursor.hpp',
|
||||
'gale/context/Fps.hpp'
|
||||
])
|
||||
if "Linux" in target.get_type():
|
||||
if "Web" in target.get_type():
|
||||
my_module.add_src_file('gale/context/SDL/Context.cpp')
|
||||
elif "Linux" in target.get_type():
|
||||
my_module.add_src_file('gale/context/X11/Context.cpp')
|
||||
# check if egami is present in the worktree: this is for the icon parsing ...
|
||||
my_module.add_optionnal_depend('egami', ["c++", "-DGALE_BUILD_EGAMI"])
|
||||
@ -150,7 +152,11 @@ def configure(target, my_module):
|
||||
"-DGALE_VERSION=\"\\\"" + tools.version_to_string(my_module.get_pkg("VERSION")) + "\\\"\""
|
||||
])
|
||||
|
||||
if "Linux" in target.get_type():
|
||||
if "Web" in target.get_type():
|
||||
my_module.add_depend([
|
||||
"SDL"
|
||||
])
|
||||
elif "Linux" in target.get_type():
|
||||
pass
|
||||
elif "Android" in target.get_type():
|
||||
my_module.add_depend(["SDK", "jvm-basics"])
|
||||
|
@ -16,24 +16,48 @@
|
||||
#include <gale/resource/Program.hpp>
|
||||
|
||||
|
||||
#define GALE_SAMPLE_VBO_VERTICES (0)
|
||||
#define GALE_SAMPLE_VBO_COLOR (1)
|
||||
|
||||
class MainApplication : public gale::Application {
|
||||
private:
|
||||
ememory::SharedPtr<gale::resource::Program> m_GLprogram;
|
||||
int32_t m_GLPosition;
|
||||
int32_t m_GLMatrix;
|
||||
int32_t m_GLColor;
|
||||
float m_angle;
|
||||
ememory::SharedPtr<gale::resource::VirtualBufferObject> m_verticesVBO;
|
||||
public:
|
||||
void onCreate(gale::Context& _context) override {
|
||||
setSize(vec2(800, 600));
|
||||
m_angle = 0.0f;
|
||||
m_GLprogram = gale::resource::Program::create("DATA:basic.prog");
|
||||
if (m_GLprogram != nullptr) {
|
||||
m_GLPosition = m_GLprogram->getAttribute("EW_coord3d");
|
||||
m_GLColor = m_GLprogram->getAttribute("EW_color");
|
||||
m_GLMatrix = m_GLprogram->getUniform("EW_MatrixTransformation");
|
||||
}
|
||||
// this is the properties of the buffer requested : "r"/"w" + "-" + buffer type "f"=flaot "i"=integer
|
||||
m_verticesVBO = gale::resource::VirtualBufferObject::create(5);
|
||||
if (m_verticesVBO == nullptr) {
|
||||
TEST_ERROR("can not instanciate VBO ...");
|
||||
return;
|
||||
}
|
||||
// TO facilitate some debugs we add a name of the VBO:
|
||||
m_verticesVBO->setName("[VBO] of basic SAMPLE");
|
||||
|
||||
m_verticesVBO->pushOnBuffer(GALE_SAMPLE_VBO_VERTICES, vec3(-0.5,-0.5,0));
|
||||
m_verticesVBO->pushOnBuffer(GALE_SAMPLE_VBO_VERTICES, vec3(0,0.5,0));
|
||||
m_verticesVBO->pushOnBuffer(GALE_SAMPLE_VBO_VERTICES, vec3(0.5,-0.5,0));
|
||||
m_verticesVBO->pushOnBuffer(GALE_SAMPLE_VBO_COLOR, etk::Color<float>(etk::color::red));
|
||||
m_verticesVBO->pushOnBuffer(GALE_SAMPLE_VBO_COLOR, etk::Color<float>(etk::color::green));
|
||||
m_verticesVBO->pushOnBuffer(GALE_SAMPLE_VBO_COLOR, etk::Color<float>(etk::color::blue));
|
||||
// update all the VBO elements ...
|
||||
m_verticesVBO->flush();
|
||||
TEST_INFO("==> Init APPL (END)");
|
||||
}
|
||||
void onDraw(gale::Context& _context) override {
|
||||
m_angle += 0.01;
|
||||
ivec2 size = getSize();
|
||||
// set the basic openGL view port: (position drawed in the windows)
|
||||
gale::openGL::setViewPort(ivec2(0,0),size);
|
||||
@ -51,31 +75,42 @@ class MainApplication : public gale::Application {
|
||||
-2, 2);
|
||||
// set internal matrix system:
|
||||
gale::openGL::setMatrix(tmpProjection);
|
||||
|
||||
vec3 vertices[3]={ vec3(-0.5,-0.5,0),
|
||||
vec3(0,0.5,0),
|
||||
vec3(0.5,-0.5,0)
|
||||
};
|
||||
etk::Color<float> color[3] = { etk::color::red,
|
||||
etk::color::green,
|
||||
etk::color::blue
|
||||
};
|
||||
#if 0
|
||||
vec3 vertices[3]={ vec3(-0.5,-0.5,0),
|
||||
vec3(0,0.5,0),
|
||||
vec3(0.5,-0.5,0)
|
||||
};
|
||||
etk::Color<float> color[3] = { etk::color::red,
|
||||
etk::color::green,
|
||||
etk::color::blue
|
||||
};
|
||||
#endif
|
||||
if (m_GLprogram == nullptr) {
|
||||
TEST_INFO("No shader ...");
|
||||
return;
|
||||
}
|
||||
//EWOL_DEBUG(" display " << m_coord.size() << " elements" );
|
||||
m_GLprogram->use();
|
||||
|
||||
// set Matrix : translation/positionMatrix
|
||||
mat4 projMatrix = gale::openGL::getMatrix();
|
||||
mat4 projMatrix = gale::openGL::getMatrix() * etk::matRotate(vec3(0,0,1),m_angle);
|
||||
mat4 camMatrix = gale::openGL::getCameraMatrix();
|
||||
mat4 tmpMatrix = projMatrix * camMatrix;
|
||||
|
||||
m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix);
|
||||
// position :
|
||||
m_GLprogram->sendAttribute(m_GLPosition, 3/*x,y,z,unused*/, vertices, 4*sizeof(float));
|
||||
// color :
|
||||
m_GLprogram->sendAttribute(m_GLColor, 4/*r,g,b,a*/, color, 4*sizeof(float));
|
||||
// Request the draw od the elements :
|
||||
#if 0
|
||||
// position:
|
||||
m_GLprogram->sendAttributePointer(m_GLPosition, m_verticesVBO, GALE_SAMPLE_VBO_VERTICES);
|
||||
// color:
|
||||
m_GLprogram->sendAttributePointer(m_GLColor, m_verticesVBO, GALE_SAMPLE_VBO_COLOR);
|
||||
#else
|
||||
// position:
|
||||
m_GLprogram->sendAttribute(m_GLPosition, 3/*x,y,z,unused*/, vertices, 4*sizeof(float));
|
||||
// color:
|
||||
m_GLprogram->sendAttribute(m_GLColor, 4/*r,g,b,a*/, color, 4*sizeof(float));
|
||||
#endif
|
||||
|
||||
// Request the draw od the elements:
|
||||
gale::openGL::drawArrays(gale::openGL::renderMode::triangle, 0, 3 /*number of points*/);
|
||||
m_GLprogram->unUse();
|
||||
// Restore context of matrix
|
||||
|
@ -3,7 +3,7 @@ precision mediump float;
|
||||
precision mediump int;
|
||||
#endif
|
||||
|
||||
// output :
|
||||
// output:
|
||||
varying vec4 f_color;
|
||||
|
||||
void main(void) {
|
||||
|
@ -3,12 +3,12 @@ precision mediump float;
|
||||
precision mediump int;
|
||||
#endif
|
||||
|
||||
// Input :
|
||||
// Input:
|
||||
attribute vec3 EW_coord3d;
|
||||
attribute vec4 EW_color;
|
||||
uniform mat4 EW_MatrixTransformation;
|
||||
|
||||
// output :
|
||||
// output:
|
||||
varying vec4 f_color;
|
||||
|
||||
void main(void) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user