aboutsummaryrefslogtreecommitdiff
path: root/redist
diff options
context:
space:
mode:
authorCharles Lohr <lohr85@gmail.com>2018-03-22 00:05:17 +0000
committerCharles Lohr <lohr85@gmail.com>2018-03-22 00:05:17 +0000
commit96d6cb357f7dbe59fdfeba73808d78fc0c0ea435 (patch)
tree39c9965dd2a4d1ee330d7dac530374d9437641a1 /redist
parentd2468fcc0bd63e163a7a0564fa37b7880e2209df (diff)
downloadlibsurvive-96d6cb357f7dbe59fdfeba73808d78fc0c0ea435.tar.gz
libsurvive-96d6cb357f7dbe59fdfeba73808d78fc0c0ea435.tar.bz2
Update rawdraw
Diffstat (limited to 'redist')
-rw-r--r--redist/CNFGCocoaNSImageDriver.m103
-rw-r--r--redist/CNFGEGLDriver.c495
-rw-r--r--redist/CNFGFunctions.h2
-rw-r--r--redist/CNFGNullDriver.c7
-rw-r--r--redist/CNFGWinDriver.c5
-rw-r--r--redist/CNFGXDriver.c3
6 files changed, 572 insertions, 43 deletions
diff --git a/redist/CNFGCocoaNSImageDriver.m b/redist/CNFGCocoaNSImageDriver.m
index 4be01da..bfdeb31 100644
--- a/redist/CNFGCocoaNSImageDriver.m
+++ b/redist/CNFGCocoaNSImageDriver.m
@@ -1,3 +1,6 @@
+//Copyright (c) 2017 <>< David Chapman - Under the MIT/x11 or NewBSD License you choose.
+//Copyright (C) 2017 Viknet, MIT/x11 License or NewBSD License you choose.
+
#import <Cocoa/Cocoa.h>
#define RASTERIZER
@@ -11,7 +14,7 @@ id app_imageView;
NSAutoreleasePool *app_pool;
int app_sw=0, app_sh=0;
int app_mouseX=0, app_mouseY=0;
-char app_mouseDown[3] = {0,0,0};
+BOOL inFullscreen = false;
void CNFGGetDimensions( short * x, short * y )
{
@@ -19,10 +22,42 @@ void CNFGGetDimensions( short * x, short * y )
*y = app_sh;
}
-void CNFGSetup( const char * WindowName, int sw, int sh )
+void CNFGSetupFullscreen( const char * WindowName, int screen_number )
+{
+ app_sw=640; app_sh=480;
+ inFullscreen = YES;
+ [NSApplication sharedApplication];
+ [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
+ app_menubar = [[NSMenu new] autorelease];
+ app_appMenuItem = [[NSMenuItem new] autorelease];
+ [app_menubar addItem:app_appMenuItem];
+ [NSApp setMainMenu:app_menubar];
+ app_appMenu = [[NSMenu new] autorelease];
+ app_appName = [[NSProcessInfo processInfo] processName];
+ app_quitTitle = [@"Quit " stringByAppendingString:app_appName];
+ app_quitMenuItem = [[[NSMenuItem alloc] initWithTitle:app_quitTitle
+ action:@selector(terminate:) keyEquivalent:@"q"] autorelease];
+ [app_appMenu addItem:app_quitMenuItem];
+ [app_appMenuItem setSubmenu:app_appMenu];
+
+ NSString *title = [[[NSString alloc] initWithCString: WindowName encoding: NSUTF8StringEncoding] autorelease];
+ app_imageView = [NSImageView new];
+ NSDictionary *fullScreenOptions = [[NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithInt:
+ (NSApplicationPresentationAutoHideMenuBar | NSApplicationPresentationAutoHideDock) ],
+ NSFullScreenModeApplicationPresentationOptions, nil] retain];
+ [app_imageView enterFullScreenMode:[[NSScreen screens] objectAtIndex:screen_number] withOptions:fullScreenOptions];
+ [app_imageView unregisterDraggedTypes];
+ CGSize app_imageSize = [app_imageView frame].size;
+ app_sw = app_imageSize.width; app_sh = app_imageSize.height;
+ [NSApp finishLaunching];
+ [NSApp updateWindows];
+ app_pool = [NSAutoreleasePool new];
+}
+
+int CNFGSetup( const char * WindowName, int sw, int sh )
{
app_sw=sw; app_sh=sh;
- [NSAutoreleasePool new];
[NSApplication sharedApplication];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
app_menubar = [[NSMenu new] autorelease];
@@ -40,10 +75,9 @@ void CNFGSetup( const char * WindowName, int sw, int sh )
styleMask:NSWindowStyleMaskBorderless | NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable backing:NSBackingStoreBuffered defer:NO]
autorelease];
- app_imageView = [[NSImageView alloc] init];
-
- NSString *title = [[NSString alloc] initWithCString: WindowName encoding: NSUTF8StringEncoding];
+ NSString *title = [[[NSString alloc] initWithCString: WindowName encoding: NSUTF8StringEncoding] autorelease];
[app_window setTitle:title];
+ app_imageView = [NSImageView new];
[app_window setContentView:app_imageView];
[app_window cascadeTopLeftFromPoint:NSMakePoint(20,20)];
[app_window makeKeyAndOrderFront:nil];
@@ -51,6 +85,7 @@ void CNFGSetup( const char * WindowName, int sw, int sh )
[NSApp finishLaunching];
[NSApp updateWindows];
app_pool = [[NSAutoreleasePool alloc] init];
+ return 0;
}
#define XK_Left 0xff51 /* Move left, left arrow */
@@ -60,12 +95,6 @@ void CNFGSetup( const char * WindowName, int sw, int sh )
#define KEY_UNDEFINED 255
#define KEY_LEFT_MOUSE 0
-// NSEvent enum types
-#define EVENT_KEY_DOWN 10
-#define EVENT_KEY_UP 11
-#define EVENT_LEFT_MOUSE_DOWN 1
-#define EVENT_LEFT_MOUSE_UP 2
-
static int keycode(key)
{
if (key < 256) return key;
@@ -80,31 +109,13 @@ static int keycode(key)
void CNFGHandleInput()
{
-printf("CNFGHandleInput\n");
-
// Quit if no open windows left
- if ([[NSApp windows] count] == 0) [NSApp terminate: nil];
- //----------------------
- // Check for mouse motion (NOTE: the mouse move event
- // has complex behavior after a mouse click.
- // we can work around this by checking mouse motion explicitly)
- //----------------------
- NSPoint location = [app_window mouseLocationOutsideOfEventStream];
- if ((int)location.x != app_mouseX || (int)location.y != app_mouseY) {
- app_mouseX = (int)location.x;
- app_mouseY = (int)location.y;
- if (app_mouseX >= 0 && app_mouseX < app_sw &&
- app_mouseY >= 0 && app_mouseY < app_sh)
- {
- HandleMotion(app_mouseX, app_mouseY, app_mouseDown[0]||app_mouseDown[1]||app_mouseDown[2]);
- }
- }
+ // if ([[NSApp windows] count] == 0) [NSApp terminate: nil];
//----------------------
// Peek at the next event
//----------------------
NSDate *app_currDate = [NSDate new];
-
// If we have events, handle them!
NSEvent *event;
for (;(event = [NSApp
@@ -113,6 +124,7 @@ printf("CNFGHandleInput\n");
inMode:NSDefaultRunLoopMode
dequeue:YES]);)
{
+ NSPoint local_point;
NSEventType type = [event type];
switch (type)
{
@@ -130,14 +142,34 @@ printf("CNFGHandleInput\n");
}
break;
+ case NSEventTypeMouseMoved:
+ case NSEventTypeLeftMouseDragged:
+ case NSEventTypeRightMouseDragged:
+ case NSEventTypeOtherMouseDragged:
+ if (inFullscreen){
+ local_point = [NSEvent mouseLocation];
+ } else {
+ if ([event window] == nil) break;
+ NSPoint event_location = event.locationInWindow;
+ local_point = [app_imageView convertPoint:event_location fromView:nil];
+ }
+ app_mouseX = fmax(fmin(local_point.x, app_sw), 0);
+ // Y coordinate must be inversed?
+ app_mouseY = fmax(fmin(app_sh - local_point.y, app_sh), 0);
+ HandleMotion(app_mouseX, app_mouseY, [NSEvent pressedMouseButtons]);
+ break;
+
case NSEventTypeLeftMouseDown:
- HandleButton(app_mouseX, app_mouseY, KEY_LEFT_MOUSE, 1);
- app_mouseDown[0]=1;
+ case NSEventTypeRightMouseDown:
+ case NSEventTypeOtherMouseDown:
+ // Button number start from 1?
+ HandleButton(app_mouseX, app_mouseY, event.buttonNumber+1, 1);
break;
case NSEventTypeLeftMouseUp:
- HandleButton(app_mouseX, app_mouseY, KEY_LEFT_MOUSE, 0);
- app_mouseDown[0]=0;
+ case NSEventTypeRightMouseUp:
+ case NSEventTypeOtherMouseUp:
+ HandleButton(app_mouseX, app_mouseY, event.buttonNumber+1, 0);
break;
default:
@@ -166,4 +198,3 @@ void CNFGUpdateScreenWithBitmap( unsigned long * data, int w, int h )
[app_imageView setNeedsDisplay:YES];
[bitmap release];
}
-
diff --git a/redist/CNFGEGLDriver.c b/redist/CNFGEGLDriver.c
new file mode 100644
index 0000000..2c3a0a1
--- /dev/null
+++ b/redist/CNFGEGLDriver.c
@@ -0,0 +1,495 @@
+/*
+ * Copyright (c) 2011-2013 Luc Verhaegen <libv@skynet.be>
+ * Copyright (c) 2018 <>< Charles Lohr
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "CNFGFunctions.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <EGL/egl.h>
+#include <GLES2/gl2.h>
+
+#define EGL_ZBITS 16
+#define EGL_IMMEDIATE_SIZE 2048
+
+#ifdef USE_EGL_X
+ #error This feature has never been completed or tested.
+ Display *XDisplay;
+ Window XWindow;
+#else
+ typedef enum
+ {
+ FBDEV_PIXMAP_DEFAULT = 0,
+ FBDEV_PIXMAP_SUPPORTS_UMP = (1<<0),
+ FBDEV_PIXMAP_ALPHA_FORMAT_PRE = (1<<1),
+ FBDEV_PIXMAP_COLORSPACE_sRGB = (1<<2),
+ FBDEV_PIXMAP_EGL_MEMORY = (1<<3) /* EGL allocates/frees this memory */
+ } fbdev_pixmap_flags;
+
+ typedef struct fbdev_window
+ {
+ unsigned short width;
+ unsigned short height;
+ } fbdev_window;
+
+ typedef struct fbdev_pixmap
+ {
+ unsigned int height;
+ unsigned int width;
+ unsigned int bytes_per_pixel;
+ unsigned char buffer_size;
+ unsigned char red_size;
+ unsigned char green_size;
+ unsigned char blue_size;
+ unsigned char alpha_size;
+ unsigned char luminance_size;
+ fbdev_pixmap_flags flags;
+ unsigned short *data;
+ unsigned int format; /* extra format information in case rgbal is not enough, especially for YUV formats */
+ } fbdev_pixmap;
+
+struct fbdev_window native_window;
+#endif
+
+
+static const char *default_vertex_shader_source =
+ "attribute vec4 aPosition; \n"
+ "attribute vec4 aColor; \n"
+ "uniform vec4 screenscale; \n"
+ " \n"
+ "varying vec4 vColor; \n"
+ " \n"
+ "void main() \n"
+ "{ \n"
+ " vColor = aColor; \n"
+ " gl_Position = vec4( -1.0, 1.0, 0.0, 0.0 ) + aPosition * screenscale; \n"
+ "} \n";
+static const char *default_fragment_shader_source =
+ "precision mediump float; \n"
+ " \n"
+ "varying vec4 vColor; \n"
+ " \n"
+ "void main() \n"
+ "{ \n"
+ " gl_FragColor = vColor; \n"
+ "} \n";
+GLuint default_vertex_shader;
+GLuint default_fragment_shader;
+GLuint default_screenscale_offset;
+
+
+static EGLint const config_attribute_list[] = {
+ EGL_RED_SIZE, 8,
+ EGL_GREEN_SIZE, 8,
+ EGL_BLUE_SIZE, 8,
+ EGL_ALPHA_SIZE, 8,
+ EGL_BUFFER_SIZE, 32,
+ EGL_STENCIL_SIZE, 0,
+ EGL_DEPTH_SIZE, EGL_ZBITS,
+ EGL_SAMPLES, 4,
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+ EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PIXMAP_BIT,
+ EGL_NONE
+};
+
+
+static EGLint window_attribute_list[] = {
+ EGL_NONE
+};
+
+static const EGLint context_attribute_list[] = {
+ EGL_CONTEXT_CLIENT_VERSION, 2,
+ EGL_NONE
+};
+
+EGLDisplay egl_display;
+EGLSurface egl_surface;
+uint32_t egl_currentcolor;
+
+uint32_t CNFGColor( uint32_t RGB ) { egl_currentcolor = RGB|((RGB<0x1000000)?0xff000000:0); }
+
+void CNFGUpdateScreenWithBitmap( unsigned long * data, int w, int h )
+{
+ fprintf( stderr, "Screen bitmap update not permitted.\n" );
+ //Not implemented
+}
+
+
+
+int egl_immediate_stride;
+int egl_immediate_size;
+int egl_immediate_draw_mode;
+int16_t egl_immediate_geo_buffer[EGL_IMMEDIATE_SIZE*4];
+int16_t * egl_immediate_geo_ptr;
+uint32_t egl_immediate_color_buffer[EGL_IMMEDIATE_SIZE*4];
+
+
+static GLfloat vVertices[] = { 0.0f, 0.5f, 0.0f,
+ -0.5f, -0.5f, 0.0f,
+ 0.5f, -0.5f, 0.0f };
+static GLfloat vColors[] = {1.0f, 0.0f, 0.0f, 1.0f,
+ 0.0f, 1.0f, 0.0f, 1.0f,
+ 0.0f, 0.0f, 1.0f, 1.0f};
+
+
+void FlushRender()
+{
+ if( egl_immediate_size && egl_immediate_draw_mode >= 0 )
+ {
+ //printf( "%d %d %d %d\n",egl_immediate_geo_buffer[0],egl_immediate_geo_buffer[1], egl_immediate_geo_buffer[2], egl_immediate_geo_buffer[3] );
+ //printf( "%d*%d ", egl_immediate_size,egl_immediate_stride );
+ glVertexAttribPointer(0, egl_immediate_stride, GL_SHORT, GL_FALSE, 0, egl_immediate_geo_buffer);
+ glEnableVertexAttribArray(0);
+ glVertexAttribPointer(1, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, egl_immediate_color_buffer);
+ glEnableVertexAttribArray(1);
+ glDrawArrays(egl_immediate_draw_mode, 0, egl_immediate_size);
+
+ egl_immediate_size = 0;
+ }
+
+ egl_immediate_geo_ptr = egl_immediate_geo_buffer;
+ egl_immediate_draw_mode = -1;
+}
+
+void CNFGTackPixel( short x1, short y1 )
+{
+ if( egl_immediate_draw_mode != GL_POINTS
+ || (egl_immediate_size+2) >= EGL_IMMEDIATE_SIZE ) FlushRender();
+ egl_immediate_geo_ptr[0] = x1;
+ egl_immediate_geo_ptr[1] = y1;
+ egl_immediate_geo_ptr += 2;
+ egl_immediate_color_buffer[egl_immediate_size] = egl_currentcolor;
+ egl_immediate_size++;
+ egl_immediate_draw_mode = GL_POINTS;
+ egl_immediate_stride = 2;
+}
+
+void CNFGTackSegment( short x1, short y1, short x2, short y2 )
+{
+ if( egl_immediate_draw_mode != GL_LINES
+ || egl_immediate_size >= EGL_IMMEDIATE_SIZE ) FlushRender();
+ egl_immediate_geo_ptr[0] = x1;
+ egl_immediate_geo_ptr[1] = y1;
+ egl_immediate_geo_ptr[2] = x2;
+ egl_immediate_geo_ptr[3] = y2;
+ egl_immediate_geo_ptr += 4;
+ egl_immediate_color_buffer[egl_immediate_size+0] = egl_currentcolor;
+ egl_immediate_color_buffer[egl_immediate_size+1] = egl_currentcolor;
+ egl_immediate_size+=2;
+ egl_immediate_draw_mode = GL_LINES;
+ egl_immediate_stride = 2;
+}
+
+void CNFGTackRectangle( short x1, short y1, short x2, short y2 )
+{
+ if( egl_immediate_draw_mode != GL_TRIANGLES
+ || (egl_immediate_size+12) >= EGL_IMMEDIATE_SIZE ) FlushRender();
+ /*
+ *-*
+ |/|
+ *-* Don't forget to go clockwise!
+ */
+ egl_immediate_geo_ptr[0] = x1;
+ egl_immediate_geo_ptr[1] = y1;
+ egl_immediate_geo_ptr[2] = x2;
+ egl_immediate_geo_ptr[3] = y1;
+ egl_immediate_geo_ptr[4] = x1;
+ egl_immediate_geo_ptr[5] = y2;
+ egl_immediate_geo_ptr[6] = x1;
+ egl_immediate_geo_ptr[7] = y2;
+ egl_immediate_geo_ptr[8] = x2;
+ egl_immediate_geo_ptr[9] = y1;
+ egl_immediate_geo_ptr[10] = x2;
+ egl_immediate_geo_ptr[11] = y2;
+ egl_immediate_geo_ptr += 12;
+ egl_immediate_color_buffer[egl_immediate_size+0] = egl_currentcolor;
+ egl_immediate_color_buffer[egl_immediate_size+1] = egl_currentcolor;
+ egl_immediate_color_buffer[egl_immediate_size+2] = egl_currentcolor;
+ egl_immediate_color_buffer[egl_immediate_size+3] = egl_currentcolor;
+ egl_immediate_color_buffer[egl_immediate_size+4] = egl_currentcolor;
+ egl_immediate_color_buffer[egl_immediate_size+5] = egl_currentcolor;
+ egl_immediate_size+=6;
+ egl_immediate_draw_mode = GL_TRIANGLES;
+ egl_immediate_stride = 2;
+}
+
+void CNFGTackPoly( RDPoint * points, int verts )
+{
+ if( egl_immediate_draw_mode != GL_TRIANGLES
+ || egl_immediate_size+verts*2 >= EGL_IMMEDIATE_SIZE ) FlushRender();
+
+ int i;
+ for( i = 0; i < verts; i++ )
+ {
+ egl_immediate_geo_ptr[0] = points[i].x;
+ egl_immediate_geo_ptr[1] = points[i].y;
+ egl_immediate_geo_ptr += 2;
+ egl_immediate_color_buffer[egl_immediate_size] = egl_currentcolor;
+ egl_immediate_size++;
+ }
+ egl_immediate_draw_mode = GL_TRIANGLES;
+ egl_immediate_stride = 2;
+}
+
+void CNFGClearFrame()
+{
+ glClearColor( (CNFGBGColor&0xff)/255.0,
+ (CNFGBGColor&0xff00)/65280.0,
+ (CNFGBGColor&0xff0000)/16711680.0,
+ ((CNFGBGColor&0xff000000)>>24)/255.0);
+ glClear(GL_COLOR_BUFFER_BIT /*| GL_DEPTH_BUFFER_BIT*/);
+}
+
+void CNFGSwapBuffers()
+{
+ FlushRender();
+ eglSwapBuffers(egl_display, egl_surface);
+}
+
+void CNFGGetDimensions( short * x, short * y )
+{
+ *x = native_window.width;
+ *y = native_window.height;
+}
+
+int CNFGSetup( const char * WindowName, int w, int h )
+{
+ int ret;
+ EGLint egl_major, egl_minor;
+ EGLConfig config;
+ EGLint num_config;
+ EGLContext context;
+ GLuint program;
+
+#ifdef USE_EGL_X
+ XDisplay = XOpenDisplay(NULL);
+ if (!XDisplay) {
+ fprintf(stderr, "Error: failed to open X display.\n");
+ return -1;
+ }
+
+ Window XRoot = DefaultRootWindow(XDisplay);
+
+ XSetWindowAttributes XWinAttr;
+ XWinAttr.event_mask = ExposureMask | PointerMotionMask;
+
+ XWindow = XCreateWindow(XDisplay, XRoot, 0, 0, WIDTH, HEIGHT, 0,
+ CopyFromParent, InputOutput,
+ CopyFromParent, CWEventMask, &XWinAttr);
+
+ Atom XWMDeleteMessage =
+ XInternAtom(XDisplay, "WM_DELETE_WINDOW", False);
+
+ XMapWindow(XDisplay, XWindow);
+ XStoreName(XDisplay, XWindow, "Mali libs test");
+ XSetWMProtocols(XDisplay, XWindow, &XWMDeleteMessage, 1);
+
+ egl_display = eglGetDisplay((EGLNativeDisplayType) XDisplay);
+#else
+ native_window.width = w;
+ native_window.height =h;
+ egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+#endif
+ if (egl_display == EGL_NO_DISPLAY) {
+ fprintf(stderr, "Error: No display found!\n");
+ return -1;
+ }
+
+ if (!eglInitialize(egl_display, &egl_major, &egl_minor)) {
+ fprintf(stderr, "Error: eglInitialise failed!\n");
+ return -1;
+ }
+
+ printf("EGL Version: \"%s\"\n",
+ eglQueryString(egl_display, EGL_VERSION));
+ printf("EGL Vendor: \"%s\"\n",
+ eglQueryString(egl_display, EGL_VENDOR));
+ printf("EGL Extensions: \"%s\"\n",
+ eglQueryString(egl_display, EGL_EXTENSIONS));
+
+ eglChooseConfig(egl_display, config_attribute_list, &config, 1,
+ &num_config);
+
+ context = eglCreateContext(egl_display, config, EGL_NO_CONTEXT,
+ context_attribute_list);
+ if (context == EGL_NO_CONTEXT) {
+ fprintf(stderr, "Error: eglCreateContext failed: 0x%08X\n",
+ eglGetError());
+ return -1;
+ }
+
+#ifdef USE_EGL_X
+ egl_surface = eglCreateWindowSurface(egl_display, config, XWindow,
+ window_attribute_list);
+#else
+ egl_surface = eglCreateWindowSurface(egl_display, config,
+ (EGLNativeWindowType)&native_window,
+ window_attribute_list);
+#endif
+ if (egl_surface == EGL_NO_SURFACE) {
+ fprintf(stderr, "Error: eglCreateWindowSurface failed: "
+ "0x%08X\n", eglGetError());
+ return -1;
+ }
+
+ int width, height;
+ if (!eglQuerySurface(egl_display, egl_surface, EGL_WIDTH, &width) ||
+ !eglQuerySurface(egl_display, egl_surface, EGL_HEIGHT, &height)) {
+ fprintf(stderr, "Error: eglQuerySurface failed: 0x%08X\n",
+ eglGetError());
+ return -1;
+ }
+ printf("Surface size: %dx%d\n", width, height);
+ native_window.width = width;
+ native_window.height = height;
+
+
+ if (!eglMakeCurrent(egl_display, egl_surface, egl_surface, context)) {
+ fprintf(stderr, "Error: eglMakeCurrent() failed: 0x%08X\n",
+ eglGetError());
+ return -1;
+ }
+
+ printf("GL Vendor: \"%s\"\n", glGetString(GL_VENDOR));
+ printf("GL Renderer: \"%s\"\n", glGetString(GL_RENDERER));
+ printf("GL Version: \"%s\"\n", glGetString(GL_VERSION));
+ printf("GL Extensions: \"%s\"\n", glGetString(GL_EXTENSIONS));
+
+ default_vertex_shader = glCreateShader(GL_VERTEX_SHADER);
+ if (!default_vertex_shader) {
+ fprintf(stderr, "Error: glCreateShader(GL_VERTEX_SHADER) "
+ "failed: 0x%08X\n", glGetError());
+ return -1;
+ }
+
+ glShaderSource(default_vertex_shader, 1, &default_vertex_shader_source, NULL);
+ glCompileShader(default_vertex_shader);
+
+ glGetShaderiv(default_vertex_shader, GL_COMPILE_STATUS, &ret);
+ if (!ret) {
+ char *log;
+
+ fprintf(stderr, "Error: vertex shader compilation failed!\n");
+ glGetShaderiv(default_vertex_shader, GL_INFO_LOG_LENGTH, &ret);
+
+ if (ret > 1) {
+ log = malloc(ret);
+ glGetShaderInfoLog(default_vertex_shader, ret, NULL, log);
+ fprintf(stderr, "%s", log);
+ }
+ return -1;
+ }
+
+ default_fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
+ if (!default_fragment_shader) {
+ fprintf(stderr, "Error: glCreateShader(GL_FRAGMENT_SHADER) "
+ "failed: 0x%08X\n", glGetError());
+ return -1;
+ }
+
+ glShaderSource(default_fragment_shader, 1, &default_fragment_shader_source, NULL);
+ glCompileShader(default_fragment_shader);
+
+ glGetShaderiv(default_fragment_shader, GL_COMPILE_STATUS, &ret);
+ if (!ret) {
+ char *log;
+
+ fprintf(stderr, "Error: fragment shader compilation failed!\n");
+ glGetShaderiv(default_fragment_shader, GL_INFO_LOG_LENGTH, &ret);
+
+ if (ret > 1) {
+ log = malloc(ret);
+ glGetShaderInfoLog(default_fragment_shader, ret, NULL, log);
+ fprintf(stderr, "%s", log);
+ }
+ return -1;
+ }
+
+ program = glCreateProgram();
+ if (!program) {
+ fprintf(stderr, "Error: failed to create program!\n");
+ return -1;
+ }
+
+ glAttachShader(program, default_vertex_shader);
+ glAttachShader(program, default_fragment_shader);
+
+ glBindAttribLocation(program, 0, "aPosition");
+ glBindAttribLocation(program, 1, "aColor");
+
+ glLinkProgram(program);
+
+ glGetProgramiv(program, GL_LINK_STATUS, &ret);
+ if (!ret) {
+ char *log;
+
+ fprintf(stderr, "Error: program linking failed!\n");
+ glGetProgramiv(program, GL_INFO_LOG_LENGTH, &ret);
+
+ if (ret > 1) {
+ log = malloc(ret);
+ glGetProgramInfoLog(program, ret, NULL, log);
+ fprintf(stderr, "%s", log);
+ }
+ return -1;
+ }
+ glUseProgram(program);
+ default_screenscale_offset = glGetUniformLocation ( program , "screenscale" );
+ glUniform4f( default_screenscale_offset, 2./width, -2./height, 1.0, 1.0 );
+
+ egl_immediate_geo_ptr = &egl_immediate_geo_buffer[0];
+
+ glLineWidth(10.0);
+ //glEnable(GL_DEPTH_TEST);
+
+ return 0;
+}
+
+void CNFGSetupFullscreen( const char * WindowName, int screen_number )
+{
+ fprintf( stderr, "You had better already be in full-screen mode.\n" );
+}
+
+void CNFGHandleInput()
+{
+
+#ifdef USE_EGL_X
+ while (1) {
+ XEvent event;
+
+ XNextEvent(XDisplay, &event);
+
+ if ((event.type == MotionNotify) ||
+ (event.type == Expose))
+ Redraw(width, height);
+ else if (event.type == ClientMessage) {
+ if (event.xclient.data.l[0] == XWMDeleteMessage)
+ break;
+ }
+ }
+ XSetWMProtocols(XDisplay, XWindow, &XWMDeleteMessage, 0);
+#endif
+}
+
+
diff --git a/redist/CNFGFunctions.h b/redist/CNFGFunctions.h
index 179a20b..1040863 100644
--- a/redist/CNFGFunctions.h
+++ b/redist/CNFGFunctions.h
@@ -34,7 +34,7 @@ void CNFGClearFrame();
void CNFGSwapBuffers();
void CNFGGetDimensions( short * x, short * y );
-void CNFGSetup( const char * WindowName, int w, int h );
+int CNFGSetup( const char * WindowName, int w, int h ); //return 0 if ok.
void CNFGSetupFullscreen( const char * WindowName, int screen_number );
void CNFGHandleInput();
diff --git a/redist/CNFGNullDriver.c b/redist/CNFGNullDriver.c
index c35884a..b50612c 100644
--- a/redist/CNFGNullDriver.c
+++ b/redist/CNFGNullDriver.c
@@ -23,10 +23,11 @@ void CNFGTearDown()
{
}
-void CNFGSetup( const char * WindowName, int sw, int sh )
+int CNFGSetup( const char * WindowName, int sw, int sh )
{
w = sw;
h = sh;
+ return 0;
}
void CNFGHandleInput()
@@ -38,13 +39,13 @@ void CNFGUpdateScreenWithBitmap( unsigned long * data, int w, int h )
{
}
-
#ifndef RASTERIZER
uint32_t CNFGColor( uint32_t RGB )
{
}
+#endif
void CNFGClearFrame()
{
@@ -70,5 +71,3 @@ void CNFGTackPoly( RDPoint * points, int verts )
{
}
-#endif
-
diff --git a/redist/CNFGWinDriver.c b/redist/CNFGWinDriver.c
index 9d1be6a..4d34e19 100644
--- a/redist/CNFGWinDriver.c
+++ b/redist/CNFGWinDriver.c
@@ -106,7 +106,7 @@ LRESULT CALLBACK MyWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
}
//This was from the article, too... well, mostly.
-void CNFGSetup( const char * name_of_window, int width, int height )
+int CNFGSetup( const char * name_of_window, int width, int height )
{
static LPSTR szClassName = "MyClass";
RECT client, window;
@@ -208,10 +208,12 @@ void CNFGSetup( const char * name_of_window, int width, int height )
MoveWindow( lsHWND, window.left, window.top, bufferx + wd, buffery + hd, 1 );
InternalHandleResize();
+ return 0;
}
void CNFGHandleInput()
{
+ int ldown = 0;
MSG msg;
while( PeekMessage( &msg, lsHWND, 0, 0xFFFF, 1 ) )
@@ -238,6 +240,7 @@ void CNFGHandleInput()
break;
}
}
+ return 0;
}
#ifndef CNFGOGL
diff --git a/redist/CNFGXDriver.c b/redist/CNFGXDriver.c
index ebaed91..91b7233 100644
--- a/redist/CNFGXDriver.c
+++ b/redist/CNFGXDriver.c
@@ -161,7 +161,7 @@ void CNFGTearDown()
CNFGClassHint = NULL;
}
-void CNFGSetup( const char * WindowName, int w, int h )
+int CNFGSetup( const char * WindowName, int w, int h )
{
CNFGDisplay = XOpenDisplay(NULL);
atexit( CNFGTearDown );
@@ -206,6 +206,7 @@ void CNFGSetup( const char * WindowName, int w, int h )
#ifdef CNFGOGL
glXMakeCurrent( CNFGDisplay, CNFGWindow, CNFGCtx );
#endif
+ return 0;
}
void CNFGHandleInput()