new demo
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@302 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
parent
3069ec7552
commit
9fd99d3ab2
6 changed files with 118 additions and 5 deletions
|
|
@ -140,7 +140,7 @@ EXAMPLES = examples/example$(EXEC) examples/rotate$(EXEC) examples/image$(EXEC)
|
||||||
ifeq ($(OPENGL),1)
|
ifeq ($(OPENGL),1)
|
||||||
L_OBJS += src/widget/opengl.o
|
L_OBJS += src/widget/opengl.o
|
||||||
OOL_OBJS += oosrc/widget/opengl.o
|
OOL_OBJS += oosrc/widget/opengl.o
|
||||||
EXAMPLES += examples/glclock$(EXEC) examples/gltriangle$(EXEC) examples/glgears$(EXEC) examples/glboing$(EXEC) examples/glcube$(EXEC)
|
EXAMPLES += examples/glclock$(EXEC) examples/gltriangle$(EXEC) examples/glgears$(EXEC) examples/glboing$(EXEC) examples/glcube$(EXEC) examples/gltripaint$(EXEC)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(VULKAN),1)
|
ifeq ($(VULKAN),1)
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,6 @@
|
||||||
#include <Mw/Milsko.h>
|
#include <Mw/Milsko.h>
|
||||||
#include <Mw/Widget/OpenGL.h>
|
#include <Mw/Widget/OpenGL.h>
|
||||||
|
|
||||||
#include <GL/gl.h>
|
|
||||||
|
|
||||||
MwWidget window, opengl, button;
|
MwWidget window, opengl, button;
|
||||||
int ow, oh;
|
int ow, oh;
|
||||||
double deg = 0;
|
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/Milsko.h>
|
||||||
#include <Mw/Widget/OpenGL.h>
|
#include <Mw/Widget/OpenGL.h>
|
||||||
|
|
||||||
#include <GL/gl.h>
|
|
||||||
|
|
||||||
MwWidget opengl;
|
MwWidget opengl;
|
||||||
|
|
||||||
static void draw(void);
|
static void draw(void);
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@
|
||||||
#define MwNmenuHandler "Cmenu"
|
#define MwNmenuHandler "Cmenu"
|
||||||
#define MwNmouseDownHandler "CmouseDownHandler"
|
#define MwNmouseDownHandler "CmouseDownHandler"
|
||||||
#define MwNmouseUpHandler "CmouseUpHandler"
|
#define MwNmouseUpHandler "CmouseUpHandler"
|
||||||
|
#define MwNmouseMoveHandler "CmouseMoveHandler"
|
||||||
#define MwNchangedHandler "CchangedHandler"
|
#define MwNchangedHandler "CchangedHandler"
|
||||||
#define MwNkeyHandler "CkeyHandler"
|
#define MwNkeyHandler "CkeyHandler"
|
||||||
#define MwNkeyReleaseHandler "CkeyReleaseHandler"
|
#define MwNkeyReleaseHandler "CkeyReleaseHandler"
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ static void llmovehandler(MwLL handle, void* data) {
|
||||||
h->mouse_point.y = p->y;
|
h->mouse_point.y = p->y;
|
||||||
|
|
||||||
MwDispatch(h, mouse_move);
|
MwDispatch(h, mouse_move);
|
||||||
|
MwDispatchUserHandler(h, MwNmouseMoveHandler, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void llkeyhandler(MwLL handle, void* data) {
|
static void llkeyhandler(MwLL handle, void* data) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue