From 651b441b91d114759c37c79bd696ba94698395f1 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Mon, 13 Oct 2025 08:27:23 +0000 Subject: [PATCH] make it dynamic alloc git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@306 b9cfdab3-6d41-4d17-bbe4-086880011989 --- examples/gltripaint.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/examples/gltripaint.c b/examples/gltripaint.c index 7bee1fd..40fc9b2 100644 --- a/examples/gltripaint.c +++ b/examples/gltripaint.c @@ -14,10 +14,10 @@ typedef struct triangle { } triangle_t; /* who needs more? :) */ -triangle_t t[128]; -int ct = 0; -int click = 0; -int mx, my; +triangle_t* t = NULL; +int ct = 0; +int click = 0; +int mx, my; static void tick(MwWidget handle, void* user, void* call) { int i; @@ -66,8 +66,15 @@ static void mouse(MwWidget handle, void* user, void* call) { t[ct].points[2 * 2 + 0] = mx; t[ct].points[2 * 2 + 1] = my; } else if(click == 3) { + triangle_t* old = t; + int i; + click = 0; ct++; + + t = malloc(sizeof(*t) * (ct + 1)); + for(i = 0; i < ct; i++) t[i] = old[i]; + free(old); } } else if(mouse->button == MwLLMouseRight) { if(click > 0) { @@ -101,6 +108,8 @@ int main() { MwViewportSetSize(viewport, 1024, 768); + t = malloc(sizeof(*t)); + opengl = MwCreateWidget(MwOpenGLClass, "opengl", MwViewportGetViewport(viewport), 0, 0, 1024, 768); hints.min_width = hints.max_width = 640;