git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@4960
ffa7fe5e-494d-0410-b361-
a75ebd5db220
endif(GTK2_FOUND)
CHECK_LIBRARY_EXISTS(freeimage FreeImage_Load "" HAVE_FREEIMAGE)
endif(GTK2_FOUND)
CHECK_LIBRARY_EXISTS(freeimage FreeImage_Load "" HAVE_FREEIMAGE)
+if (USE_OPENGLES OR USE_OPENGLES2)
+ CHECK_LIBRARY_EXISTS(EGL eglInitialize "" HAVE_EGL)
+endif(USE_OPENGLES OR USE_OPENGLES2)
if (FREETYPE_FOUND)
if (OPENGL_FOUND AND OPENGL_GLU_FOUND AND GLUT_FOUND AND OPENGL_INCLUDE_DIR)
message (STATUS "opengl found: ${OPENGL_gl_LIBRARY}")
include_directories(${OPENGL_INCLUDE_DIR})
if (FREETYPE_FOUND)
if (OPENGL_FOUND AND OPENGL_GLU_FOUND AND GLUT_FOUND AND OPENGL_INCLUDE_DIR)
message (STATUS "opengl found: ${OPENGL_gl_LIBRARY}")
include_directories(${OPENGL_INCLUDE_DIR})
- set(GRAPHICS_OPENGL_LIBRARY ${OPENGL_gl_LIBRARY};${OPENGL_glu_LIBRARY};${GLUT_glut_LIBRARY})
+ if (USE_OPENGLES2)
+ set(USE_OPENGLES TRUE)
+ set(GRAPHICS_OPENGL_LIBRARY GLESv2 EGL)
+ elseif (USE_OPENGLES)
+ set(GRAPHICS_OPENGL_LIBRARY GLESv1_CM EGL)
+ else()
+ set(GRAPHICS_OPENGL_LIBRARY ${OPENGL_gl_LIBRARY};${OPENGL_glu_LIBRARY};${GLUT_glut_LIBRARY})
+ endif(USE_OPENGLES2)
if (HAVE_FREEIMAGE)
list(APPEND GRAPHICS_OPENGL_LIBRARY freeimage)
endif(HAVE_FREEIMAGE)
if (HAVE_FREEIMAGE)
list(APPEND GRAPHICS_OPENGL_LIBRARY freeimage)
endif(HAVE_FREEIMAGE)
message (STATUS "opengl not found")
endif()
else()
message (STATUS "opengl not found")
endif()
else()
- message (STATUS "no glc implementation found. Install Quesoglc for OpenGL support")
-endif(QUESOGLC_FOUND AND FREETYPE_FOUND)
+ message (STATUS "no Freetype found")
+endif(FREETYPE_FOUND)
if(SDL_FOUND AND SDLIMAGE_FOUND AND FREETYPE_FOUND)
set(SDL_IMAGE 1)
if(SDL_FOUND AND SDLIMAGE_FOUND AND FREETYPE_FOUND)
set(SDL_IMAGE 1)
#cmakedefine HAVE_ENDIAN_H 1
#cmakedefine HAVE_FREEIMAGE 1
#cmakedefine HAVE_ENDIAN_H 1
#cmakedefine HAVE_FREEIMAGE 1
+
+#cmakedefine USE_OPENGLES 1
+
+#cmakedefine USE_OPENGLES2 1
-module_add_library(graphics_opengl graphics_opengl.c)
+set(graphics_opengl_SOURCES graphics_opengl.c)
+if (USE_OPENGLES)
+ LIST(APPEND graphics_opengl_SOURCES window.c)
+endif (USE_OPENGLES)
+module_add_library(graphics_opengl ${graphics_opengl_SOURCES})
* Boston, MA 02110-1301, USA.
*/
* Boston, MA 02110-1301, USA.
*/
-#define USE_OPENGLES 0
-#define USE_OPENGLES2 0
#define USE_FLOAT 0
#define REQUIRES_POWER_OF_2 0
#define USE_FLOAT 0
#define REQUIRES_POWER_OF_2 0
#include <FreeImage.h>
#endif
#include <FreeImage.h>
#endif
-#if USE_OPENGLES
-#if USE_OPENGLES2
+#ifdef USE_OPENGLES
+#ifdef USE_OPENGLES2
#include <GLES2/gl2.h>
#include <EGL/egl.h>
#undef USE_FLOAT
#include <GLES2/gl2.h>
#include <EGL/egl.h>
#undef USE_FLOAT
void (*button_callback) (void *data, int press, int button,
struct point * p);
void *button_callback_data;
void (*button_callback) (void *data, int press, int button,
struct point * p);
void *button_callback_data;
GLuint program;
GLint mvp_location, position_location, color_location, texture_position_location, use_texture_location, texture_location;
#else
GLuint program;
GLint mvp_location, position_location, color_location, texture_position_location, use_texture_location, texture_location;
#else
//hastable for uncompressed image data
static GHashTable *hImageData;
//hastable for uncompressed image data
static GHashTable *hImageData;
#else
/* prototypes */
void APIENTRY tessBeginCB(GLenum which);
#else
/* prototypes */
void APIENTRY tessBeginCB(GLenum which);
static void resize_callback(int w, int h);
static void glut_close();
static void resize_callback(int w, int h);
static void glut_close();
const char vertex_src [] =
" \
attribute vec2 position; \
const char vertex_src [] =
" \
attribute vec2 position; \
static void
set_color(struct graphics_priv *gr, struct graphics_gc_priv *gc)
{
static void
set_color(struct graphics_priv *gr, struct graphics_gc_priv *gc)
{
GLfloat col[4];
col[0]=gc->fr;
col[1]=gc->fg;
GLfloat col[4];
col[0]=gc->fr;
col[1]=gc->fg;
x[i*2]=glF(p[i].x);
x[i*2+1]=glF(p[i].y);
}
x[i*2]=glF(p[i].x);
x[i*2+1]=glF(p[i].y);
}
glVertexAttribPointer (gr->position_location, 2, GL_FLOAT, 0, 0, x );
#else
glVertexPointer(2, GL_F, 0, x);
glVertexAttribPointer (gr->position_location, 2, GL_FLOAT, 0, 0, x );
#else
glVertexPointer(2, GL_F, 0, x);
x[2]+=glF(1);
x[3]+=glF(1);
x[7]+=glF(1);
x[2]+=glF(1);
x[3]+=glF(1);
x[7]+=glF(1);
glUniform1i(gr->use_texture_location, 1);
glEnableVertexAttribArray(gr->texture_position_location);
glVertexAttribPointer (gr->texture_position_location, 2, GL_FLOAT, 0, 0, x );
glUniform1i(gr->use_texture_location, 1);
glEnableVertexAttribArray(gr->texture_position_location);
glVertexAttribPointer (gr->texture_position_location, 2, GL_FLOAT, 0, 0, x );
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
draw_rectangle_es(gr, p, w, h);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
draw_rectangle_es(gr, p, w, h);
glUniform1i(gr->use_texture_location, 0);
glDisableVertexAttribArray(gr->texture_position_location);
#else
glUniform1i(gr->use_texture_location, 0);
glDisableVertexAttribArray(gr->texture_position_location);
#else
&& !gr->overlay_enabled)) {
return;
}
&& !gr->overlay_enabled)) {
return;
}
-#if !USE_OPENGLES || USE_OPENGLES2
+#if !defined(USE_OPENGLES) || defined(USE_OPENGLES2)
glLineWidth(gc->linewidth);
#endif
glLineWidth(gc->linewidth);
#endif
set_color(gr, gc);
draw_array(gr, p, count, GL_LINE_STRIP);
#else
set_color(gr, gc);
draw_array(gr, p, count, GL_LINE_STRIP);
#else
#else
void APIENTRY
tessCombineCB(GLdouble c[3], void *d[4], GLfloat w[4], void **out)
#else
void APIENTRY
tessCombineCB(GLdouble c[3], void *d[4], GLfloat w[4], void **out)
draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc,
struct point *p, int count)
{
draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc,
struct point *p, int count)
{
if ((gr->parent && !gr->parent->overlay_enabled)
|| (gr->parent && gr->parent->overlay_enabled
&& !gr->overlay_enabled)) {
return;
}
if ((gr->parent && !gr->parent->overlay_enabled)
|| (gr->parent && gr->parent->overlay_enabled
&& !gr->overlay_enabled)) {
return;
}
set_color(gr, gc);
draw_array(gr, p, count, GL_LINE_STRIP);
#else
set_color(gr, gc);
draw_array(gr, p, count, GL_LINE_STRIP);
#else
return; // failed to create tessellation object, return 0
GLdouble quad1[count][3];
return; // failed to create tessellation object, return 0
GLdouble quad1[count][3];
for (i = 0; i < count; i++) {
quad1[i][0] = (GLdouble) (p[i].x);
quad1[i][1] = (GLdouble) (p[i].y);
for (i = 0; i < count; i++) {
quad1[i][0] = (GLdouble) (p[i].x);
quad1[i][1] = (GLdouble) (p[i].y);
&& !gr->overlay_enabled)) {
return;
}
&& !gr->overlay_enabled)) {
return;
}
set_color(gr, gc);
draw_rectangle_es(gr, p, w, h);
#else
set_color(gr, gc);
draw_rectangle_es(gr, p, w, h);
#else
draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc,
struct point *p, int r)
{
draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc,
struct point *p, int r)
{
#else
if ((gr->parent && !gr->parent->overlay_enabled)
|| (gr->parent && gr->parent->overlay_enabled
#else
if ((gr->parent && !gr->parent->overlay_enabled)
|| (gr->parent && gr->parent->overlay_enabled
32, stride,
&white,
&transparent);
32, stride,
&white,
&transparent);
struct point p;
p.x=((x + g->x) >> 6)-1;
p.y=((y + g->y) >> 6)-1;
struct point p;
p.x=((x + g->x) >> 6)-1;
p.y=((y + g->y) >> 6)-1;
&black,
&white,
&transparent);
&black,
&white,
&transparent);
struct point p;
p.x=(x + g->x) >> 6;
p.y=(y + g->y) >> 6;
struct point p;
p.x=(x + g->x) >> 6;
p.y=(y + g->y) >> 6;
&black,
&white,
&transparent);
&black,
&white,
&transparent);
struct point p;
p.x=(x + g->x) >> 6;
p.y=(y + g->y) >> 6;
struct point p;
p.x=(x + g->x) >> 6;
p.y=(y + g->y) >> 6;
draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg,
struct point *p, struct graphics_image_priv *img)
{
draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg,
struct point *p, struct graphics_image_priv *img)
{
draw_image_es(gr, p, img->w, img->h, img->data);
#else
if ((gr->parent && !gr->parent->overlay_enabled)
draw_image_es(gr, p, img->w, img->h, img->data);
#else
if ((gr->parent && !gr->parent->overlay_enabled)
static void
handle_mouse_queue()
{
static void
handle_mouse_queue()
{
#else
static locked = 0;
if (!locked) {
#else
static locked = 0;
if (!locked) {
static int
redraw_screen(struct graphics_priv *gr)
{
static int
redraw_screen(struct graphics_priv *gr)
{
#else
time_t curr_time = time(0);
graphics_priv_root->dirty = 0;
#else
time_t curr_time = time(0);
graphics_priv_root->dirty = 0;
/*filters call to redraw in overlay enabled(map) mode*/
static void
redraw_filter(struct graphics_priv *gr)
/*filters call to redraw in overlay enabled(map) mode*/
static void
redraw_filter(struct graphics_priv *gr)
draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
{
if (gr->parent) { //overlay
draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
{
if (gr->parent) { //overlay
#else
if (mode == draw_mode_begin) {
glNewList(gr->DLid, GL_COMPILE);
#else
if (mode == draw_mode_begin) {
glNewList(gr->DLid, GL_COMPILE);
#endif
} else { //root graphics
if (mode == draw_mode_begin) {
#endif
} else { //root graphics
if (mode == draw_mode_begin) {
#else
glNewList(gr->DLid, GL_COMPILE);
#endif
}
if (mode == draw_mode_end) {
#else
glNewList(gr->DLid, GL_COMPILE);
#endif
}
if (mode == draw_mode_end) {
eglSwapBuffers(egldisplay, eglwindow);
#else
glEndList();
eglSwapBuffers(egldisplay, eglwindow);
#else
glEndList();
static GLuint
load_shader(const char *shader_source, GLenum type)
{
static GLuint
load_shader(const char *shader_source, GLenum type)
{
if (!strcmp(type, "gtk_widget")) {
fprintf(stderr,
"Currently GTK gui is not yet supported with opengl graphics driver\n");
if (!strcmp(type, "gtk_widget")) {
fprintf(stderr,
"Currently GTK gui is not yet supported with opengl graphics driver\n");
}
if (strcmp(type, "window") == 0) {
struct window *win;
}
if (strcmp(type, "window") == 0) {
struct window *win;
GLuint vertexShader;
GLuint fragmentShader;
GLuint textures;
GLuint vertexShader;
GLuint fragmentShader;
GLuint textures;
glClearColor ( 0.4 , 0.4 , 0.4 , 1);
#endif
glClear ( GL_COLOR_BUFFER_BIT );
glClearColor ( 0.4 , 0.4 , 0.4 , 1);
#endif
glClear ( GL_COLOR_BUFFER_BIT );
this->program=glCreateProgram();
vertexShader = load_shader(vertex_src, GL_VERTEX_SHADER);
fragmentShader = load_shader(fragment_src, GL_FRAGMENT_SHADER);
this->program=glCreateProgram();
vertexShader = load_shader(vertex_src, GL_VERTEX_SHADER);
fragmentShader = load_shader(fragment_src, GL_FRAGMENT_SHADER);
glGenTextures(1, &textures);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textures);
glGenTextures(1, &textures);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textures);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
#endif
#endif
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
#endif
#endif
win->disable_suspend = graphics_opengl_disable_suspend;
return win;
} else {
win->disable_suspend = graphics_opengl_disable_suspend;
return win;
} else {
return NULL;
#else
return &this->DLid;
return NULL;
#else
return &this->DLid;
this->next = gr->overlays;
gr->overlays = this;
this->next = gr->overlays;
gr->overlays = this;
#else
this->DLid = glGenLists(1);
#endif
#else
this->DLid = glGenLists(1);
#endif
static gboolean
graphics_opengl_idle(void *data)
{
static gboolean
graphics_opengl_idle(void *data)
{
static int opengl_init_ok = 0;
if (!opengl_init_ok) {
callback_list_call_attr_2(graphics_priv_root->cbl,
static int opengl_init_ok = 0;
if (!opengl_init_ok) {
callback_list_call_attr_2(graphics_priv_root->cbl,
handle_mouse_queue();
}
return TRUE;
handle_mouse_queue();
}
return TRUE;
static void
ProcessNormalKeys(unsigned char key_in, int x, int y)
static void
ProcessNormalKeys(unsigned char key_in, int x, int y)
resize_callback(int w, int h)
{
glViewport(0, 0, w, h);
resize_callback(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
#ifdef MIRRORED_VIEW
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
#ifdef MIRRORED_VIEW
#else
glOrthof(glF(0), glF(w), glF(h), glF(0), glF(1), glF(-1));
#endif
#else
glOrthof(glF(0), glF(w), glF(h), glF(0), glF(1), glF(-1));
#endif
graphics_priv_root->width = w;
graphics_priv_root->height = h;
graphics_priv_root->width = w;
graphics_priv_root->height = h;
char *cmdline = "";
int argc = 0;
char *cmdline = "";
int argc = 0;
glutInit(&argc, &cmdline);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInit(&argc, &cmdline);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
graphics_priv_root->width = this->width;
graphics_priv_root->height = this->height;
graphics_priv_root->width = this->width;
graphics_priv_root->height = this->height;
glutMotionFunc(motion_notify);
glutPassiveMotionFunc(motion_notify);
glutMouseFunc(click_notify);
glutMotionFunc(motion_notify);
glutPassiveMotionFunc(motion_notify);
glutMouseFunc(click_notify);
glutCloseFunc(glut_close);
#endif
this->DLid = glGenLists(1);
glutCloseFunc(glut_close);
#endif
this->DLid = glGenLists(1);
g_timeout_add(G_PRIORITY_DEFAULT + 10, graphics_opengl_idle, NULL);
/*this will only refresh screen in map(overlay enabled) mode */
g_timeout_add(G_PRIORITY_DEFAULT + 1000, redraw_filter, this);
g_timeout_add(G_PRIORITY_DEFAULT + 10, graphics_opengl_idle, NULL);
/*this will only refresh screen in map(overlay enabled) mode */
g_timeout_add(G_PRIORITY_DEFAULT + 1000, redraw_filter, this);
//create hash table for uncompressed image data
hImageData = g_hash_table_new(g_str_hash, g_str_equal);
//create hash table for uncompressed image data
hImageData = g_hash_table_new(g_str_hash, g_str_equal);
-#define USE_OPENGLES2 1
-
-#if USE_OPENGLES2
+#include "config.h"
+#ifdef USE_OPENGLES2
#include <GLES2/gl2.h>
#include <EGL/egl.h>
#else
#include <GLES2/gl2.h>
#include <EGL/egl.h>
#else
Display *dpy;
Window window;
Display *dpy;
Window window;
static EGLint attributeList[] = {
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
static EGLint attributeList[] = {
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
XVisualInfo *vi, tmp;
int vid, n;
XVisualInfo *vi, tmp;
int vid, n;
EGLint aEGLContextAttributes[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
EGLint aEGLContextAttributes[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
dbg(0, "can't find requested config\n");
return 0;
}
dbg(0, "can't find requested config\n");
return 0;
}
cx = eglCreateContext(egldisplay, config[0], EGL_NO_CONTEXT, aEGLContextAttributes);
#else
cx = eglCreateContext(egldisplay, config[0], EGL_NO_CONTEXT, NULL);
cx = eglCreateContext(egldisplay, config[0], EGL_NO_CONTEXT, aEGLContextAttributes);
#else
cx = eglCreateContext(egldisplay, config[0], EGL_NO_CONTEXT, NULL);