fixed simple draw_cursor
[retroray] / src / modern / main.c
index 066c431..e60329f 100644 (file)
@@ -20,7 +20,9 @@ along with this program.  If not, see <https://www.gnu.org/licenses/>.
 #include <assert.h>
 #include "miniglut.h"
 #include "app.h"
+#include "logger.h"
 
+static void display(void);
 static void reshape(int x, int y);
 static void keydown(unsigned char key, int x, int y);
 static void keyup(unsigned char key, int x, int y);
@@ -29,6 +31,7 @@ static void skeyup(int key, int x, int y);
 static void mouse(int bn, int st, int x, int y);
 static void motion(int x, int y);
 static int translate_skey(int key);
+static void draw_cursor(int x, int y);
 
 #if defined(__unix__) || defined(unix)
 #include <GL/glx.h>
@@ -52,7 +55,7 @@ int main(int argc, char **argv)
        glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
        glutCreateWindow("RetroRay");
 
-       glutDisplayFunc(app_display);
+       glutDisplayFunc(display);
        glutReshapeFunc(reshape);
        glutKeyboardFunc(keydown);
        glutKeyboardUpFunc(keyup);
@@ -77,7 +80,11 @@ int main(int argc, char **argv)
        wgl_swap_interval_ext = wglGetProcAddress("wglSwapIntervalEXT");
 #endif
 
-       app_reshape(glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));
+       win_width = glutGet(GLUT_WINDOW_WIDTH);
+       win_height = glutGet(GLUT_WINDOW_HEIGHT);
+       win_aspect = (float)win_width / win_height;
+
+       init_logger();
 
        if(app_init() == -1) {
                return 1;
@@ -173,6 +180,14 @@ void app_vsync(int vsync)
 #endif
 
 
+static void display(void)
+{
+       app_display();
+
+       draw_cursor(mouse_x, mouse_y);
+
+       app_swap_buffers();
+}
 
 static void reshape(int x, int y)
 {
@@ -232,7 +247,7 @@ static int translate_skey(int key)
        case GLUT_KEY_PAGE_UP:
                return KEY_PGUP;
        case GLUT_KEY_PAGE_DOWN:
-               return KEY_PGDOWN;
+               return KEY_PGDN;
        case GLUT_KEY_HOME:
                return KEY_HOME;
        case GLUT_KEY_END:
@@ -247,3 +262,17 @@ static int translate_skey(int key)
 
        return -1;
 }
+
+static void draw_cursor(int x, int y)
+{
+       int i;
+       uint32_t *fbptr = framebuf + y * win_width + x;
+
+       for(i=0; i<3; i++) {
+               int offs = i + 1;
+               if(y > offs) fbptr[-win_width * offs] ^= 0xffffff;
+               if(y < win_height - offs - 1) fbptr[win_width * offs] ^= 0xffffff;
+               if(x > offs) fbptr[-offs] ^= 0xffffff;
+               if(x < win_width - offs - 1) fbptr[offs] ^= 0xffffff;
+       }
+}