1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#ifdef USE_OPENGL
#ifdef WIN32
#include <windows.h>
#endif
#include <GL/gl.h>
#include <stdlib.h>
#include <stdio.h>
#include "iup.h"
#include "iupgl.h"
static int button_cb(Ihandle *ih,int but,int pressed,int x,int y,char* status)
{
printf("BUTTON_CB(but=%c (pressed=%d), x=%d, y=%d [%s])\n",(char)but,pressed,x,y, status);
return IUP_DEFAULT;
}
static int action(Ihandle *ih)
{
IupGLMakeCurrent(ih);
glClearColor(1.0, 0.0, 1.0, 1.f); /* pink */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1.0,0.0,0.0); /* red */
glBegin(GL_QUADS);
glVertex2f(0.9f,0.9f);
glVertex2f(0.9f,-0.9f);
glVertex2f(-0.9f,-0.9f);
glVertex2f(-0.9f,0.9f);
glEnd();
IupGLSwapBuffers(ih);
return IUP_DEFAULT;
}
void GLCanvasTest(void)
{
Ihandle *dlg, *canvas, *box;
IupGLCanvasOpen();
box = IupVbox(NULL);
IupSetAttribute(box, "MARGIN", "5x5");
canvas = IupGLCanvas(NULL);
IupSetCallback(canvas, "ACTION", action);
IupSetAttribute(canvas, "BUFFER", "DOUBLE");
IupSetAttribute(canvas, "BORDER", "NO");
IupSetAttribute(canvas, "RASTERSIZE", "300x200");
IupSetCallback(canvas, "BUTTON_CB", (Icallback)button_cb);
IupAppend(box, canvas);
dlg = IupDialog(box);
IupSetAttribute(dlg, "TITLE", "IupGLCanvas Test");
IupMap(dlg);
IupGLMakeCurrent(canvas);
printf("Vendor: %s\n", glGetString(GL_VENDOR));
printf("Renderer: %s\n", glGetString(GL_RENDERER));
printf("Version: %s\n", glGetString(GL_VERSION));
IupShowXY(dlg, IUP_CENTER, IUP_CENTER);
}
#ifndef BIG_TEST
int main(int argc, char* argv[])
{
IupOpen(&argc, &argv);
IupGLCanvasOpen();
GLCanvasTest();
IupMainLoop();
IupClose();
return EXIT_SUCCESS;
}
#endif
#endif
|