-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGL_image_display-test-glut.c
122 lines (100 loc) · 3.44 KB
/
GL_image_display-test-glut.c
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Tests the one-time GLUT-based opengl render.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <getopt.h>
#include <string.h>
#include <FreeImage.h>
#include <math.h>
#include <epoxy/gl.h>
#include <GL/freeglut.h>
#include "GL_image_display.h"
#include "util.h"
GL_image_display_context_t ctx;
int main(int argc, char* argv[])
{
if(argc != 2 && argc != 3)
{
fprintf(stderr,
"Need one or two images on the commandline. If two, I flip between them at 1Hz\n");
return 1;
}
if( !GL_image_display_init( &ctx, true) )
return 1;
char** images = &argv[1];
int i_image = 0;
if( !GL_image_display_update_image(&ctx,0,
images[i_image],
NULL,0,0,0,0) )
{
fprintf(stderr, "GL_image_display_update_image() failed\n");
return 1;
}
if( !GL_image_display_set_panzoom(&ctx, 1580, 900, 3500) )
{
fprintf(stderr, "GL_image_display_set_panzoom() failed\n");
return 1;
}
if( !GL_image_display_set_lines(&ctx,
((const GL_image_display_line_segments_t[]) {
{ .segments = {.Nsegments = 1,
.color_rgb = {1.f,0.f,0.f}},
.points = ((float[]){63, 113,
937,557})},
{ .segments = {.Nsegments = 2,
.color_rgb = {0.f,1.f,0.f}},
.points = ((float[]){1749,645,
1597,100,
1597,100,
1247,224})}
}),
2 ))
{
fprintf(stderr, "GL_image_display_set_lines() failed\n");
return 1;
}
void timerfunc(int cookie __attribute__((unused)))
{
i_image = 1 - i_image;
if( !GL_image_display_update_image(&ctx,0,
images[i_image],
NULL,0,0,0,0) )
{
fprintf(stderr, "GL_image_display_update_image() failed\n");
return;
}
glutPostRedisplay();
glutTimerFunc(1000, timerfunc, 0);
}
void window_display(void)
{
GL_image_display_redraw(&ctx);
glutSwapBuffers();
}
void window_keyPressed(unsigned char key,
int x __attribute__((unused)) ,
int y __attribute__((unused)) )
{
switch (key)
{
case 'q':
case 27:
// Need both to avoid a segfault. This works differently with
// different opengl drivers
glutExit();
exit(0);
}
glutPostRedisplay();
}
void _GL_image_display_resized(int width, int height)
{
GL_image_display_resize_viewport(&ctx, width, height);
}
glutDisplayFunc (window_display);
glutKeyboardFunc(window_keyPressed);
glutReshapeFunc (_GL_image_display_resized);
if(argc == 3)
glutTimerFunc(1000, timerfunc, 0);
glutMainLoop();
return 0;
}