mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-06 17:39:45 +00:00
new demo
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@302 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -2,8 +2,6 @@
|
||||
#include <Mw/Milsko.h>
|
||||
#include <Mw/Widget/OpenGL.h>
|
||||
|
||||
#include <GL/gl.h>
|
||||
|
||||
MwWidget window, opengl, button;
|
||||
int ow, oh;
|
||||
double deg = 0;
|
||||
|
||||
115
examples/gltripaint.c
Normal file
115
examples/gltripaint.c
Normal file
@@ -0,0 +1,115 @@
|
||||
/* $Id$ */
|
||||
#include <Mw/Milsko.h>
|
||||
#include <Mw/Widget/OpenGL.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
MwWidget opengl;
|
||||
|
||||
typedef struct triangle {
|
||||
int points[3 * 2];
|
||||
double r;
|
||||
double g;
|
||||
double b;
|
||||
} triangle_t;
|
||||
|
||||
/* who needs more? :) */
|
||||
triangle_t t[128];
|
||||
int ct = 0;
|
||||
int click = 0;
|
||||
int mx, my;
|
||||
|
||||
static void tick(MwWidget handle, void* user, void* call) {
|
||||
int i;
|
||||
int w = MwGetInteger(opengl, MwNwidth);
|
||||
int h = MwGetInteger(opengl, MwNheight);
|
||||
|
||||
MwOpenGLMakeCurrent(opengl);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(0, w, h, 0, -1, 1);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
for(i = 0; i < ct + (click == 2 ? 1 : 0); i++) {
|
||||
int j;
|
||||
glBegin(GL_TRIANGLES);
|
||||
glColor3d(t[i].r, t[i].g, t[i].b);
|
||||
for(j = 0; j < 3; j++) {
|
||||
glVertex2d(t[i].points[j * 2 + 0], t[i].points[j * 2 + 1]);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
MwOpenGLSwapBuffer(opengl);
|
||||
}
|
||||
|
||||
static void mouse(MwWidget handle, void* user, void* call) {
|
||||
MwLLMouse* mouse = call;
|
||||
if(mouse->button == MwLLMouseLeft) {
|
||||
t[ct].points[click * 2 + 0] = mouse->point.x;
|
||||
t[ct].points[click * 2 + 1] = mouse->point.y;
|
||||
click++;
|
||||
if(click == 1) {
|
||||
t[ct].r = rand() % 65536;
|
||||
t[ct].g = rand() % 65536;
|
||||
t[ct].b = rand() % 65536;
|
||||
|
||||
t[ct].r /= 65535;
|
||||
t[ct].g /= 65535;
|
||||
t[ct].b /= 65535;
|
||||
} else if(click == 2) {
|
||||
t[ct].points[2 * 2 + 0] = mx;
|
||||
t[ct].points[2 * 2 + 1] = my;
|
||||
} else if(click == 3) {
|
||||
click = 0;
|
||||
ct++;
|
||||
}
|
||||
} else if(mouse->button == MwLLMouseRight) {
|
||||
if(click > 0) {
|
||||
click = 0;
|
||||
} else if(ct > 0) {
|
||||
ct--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void mouse_move(MwWidget handle, void* user, void* call) {
|
||||
MwPoint* point = call;
|
||||
mx = point->x;
|
||||
my = point->y;
|
||||
if(click == 2) {
|
||||
t[ct].points[2 * 2 + 0] = point->x;
|
||||
t[ct].points[2 * 2 + 1] = point->y;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwSizeHints hints;
|
||||
MwWidget window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 640, 480,
|
||||
MwNtitle, "tripaint",
|
||||
NULL);
|
||||
MwWidget viewport = MwCreateWidget(MwViewportClass, "viewport", window, 5, 5, 630, 470 - 16 - 5);
|
||||
|
||||
MwVaCreateWidget(MwLabelClass, "label", window, 5, 470 - 16 + 5, 630, 16,
|
||||
MwNtext, "Press left click to draw triangle, right click to undo",
|
||||
NULL);
|
||||
|
||||
MwViewportSetSize(viewport, 1024, 768);
|
||||
|
||||
opengl = MwCreateWidget(MwOpenGLClass, "opengl", MwViewportGetViewport(viewport), 0, 0, 1024, 768);
|
||||
|
||||
hints.min_width = hints.max_width = 640;
|
||||
hints.min_height = hints.max_height = 480;
|
||||
MwVaApply(window, MwNsizeHints, &hints, NULL);
|
||||
|
||||
MwAddUserHandler(window, MwNtickHandler, tick, NULL);
|
||||
MwAddUserHandler(opengl, MwNmouseDownHandler, mouse, NULL);
|
||||
MwAddUserHandler(opengl, MwNmouseMoveHandler, mouse_move, NULL);
|
||||
|
||||
MwLoop(window);
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
#include <Mw/Milsko.h>
|
||||
#include <Mw/Widget/OpenGL.h>
|
||||
|
||||
#include <GL/gl.h>
|
||||
|
||||
MwWidget opengl;
|
||||
|
||||
static void draw(void);
|
||||
|
||||
Reference in New Issue
Block a user