|
| 1 | +#include <OpenGL/gl.h> |
| 2 | +#include <OpenGL/glu.h> |
| 3 | +#include <GLUT/glut.h> |
| 4 | + |
| 5 | +#include <stdio.h> |
| 6 | +#include <stdlib.h> |
| 7 | +#include <string.h> |
| 8 | +#include <math.h> |
| 9 | + |
| 10 | +#include "vector_display.h" |
| 11 | +#include "vector_font_simplex.h" |
| 12 | + |
| 13 | +vector_display_t *display; |
| 14 | + |
| 15 | +void myInit() { |
| 16 | + int rc; |
| 17 | + rc = vector_display_new(&display, 2048, 1536); |
| 18 | + if (rc != 0) { |
| 19 | + printf("Failed to create vector display: rc=%d", rc); |
| 20 | + exit(1); |
| 21 | + } |
| 22 | + |
| 23 | + rc = vector_display_setup(display); |
| 24 | + if (rc != 0) { |
| 25 | + printf("Failed to setup vector display: rc=%d", rc); |
| 26 | + exit(1); |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +static void draw_wheel(vector_display_t *display, double angle, double x, double y, double radius) { |
| 31 | + double spokeradius = radius - 2.0f; |
| 32 | + // draw spokes |
| 33 | + vector_display_draw(display, |
| 34 | + x + spokeradius * sin(angle), |
| 35 | + y - spokeradius * cos(angle), |
| 36 | + x - spokeradius * sin(angle), |
| 37 | + y + spokeradius * cos(angle)); |
| 38 | + vector_display_draw(display, |
| 39 | + x + spokeradius * sin(angle + M_PI / 4.0f), |
| 40 | + y - spokeradius * cos(angle + M_PI / 4.0f), |
| 41 | + x - spokeradius * sin(angle + M_PI / 4.0f), |
| 42 | + y + spokeradius * cos(angle + M_PI / 4.0f)); |
| 43 | + vector_display_draw(display, |
| 44 | + x + spokeradius * sin(angle + M_PI / 2.0f), |
| 45 | + y - spokeradius * cos(angle + M_PI / 2.0f), |
| 46 | + x - spokeradius * sin(angle + M_PI / 2.0f), |
| 47 | + y + spokeradius * cos(angle + M_PI / 2.0f)); |
| 48 | + vector_display_draw(display, |
| 49 | + x + spokeradius * sin(angle + 3.0f * M_PI / 4.0f), |
| 50 | + y - spokeradius * cos(angle + 3.0f * M_PI / 4.0f), |
| 51 | + x - spokeradius * sin(angle + 3.0f * M_PI / 4.0f), |
| 52 | + y + spokeradius * cos(angle + 3.0f * M_PI / 4.0f)); |
| 53 | + |
| 54 | + double edgeangle = 0.0f; |
| 55 | + double angadjust = 0.0f; |
| 56 | + |
| 57 | + vector_display_begin_draw(display, |
| 58 | + x + radius * sin(angle + edgeangle + angadjust), |
| 59 | + y - radius * cos(angle + edgeangle + angadjust)); |
| 60 | + for (edgeangle = 0; edgeangle < 2 * M_PI - 0.001; edgeangle += M_PI/4.0f) { |
| 61 | + vector_display_draw_to(display, |
| 62 | + x + radius * sin(angle + edgeangle + M_PI / 4.0f - angadjust), |
| 63 | + y - radius * cos(angle + edgeangle + M_PI / 4.0f - angadjust)); |
| 64 | + } |
| 65 | + vector_display_end_draw(display); |
| 66 | +} |
| 67 | + |
| 68 | +static void draw_circle(vector_display_t *display, double x, double y, double radius, double steps) { |
| 69 | + double edgeangle = 0.0f; |
| 70 | + double angadjust = 0.0f; |
| 71 | + |
| 72 | + double step = M_PI * 2 / steps; |
| 73 | + |
| 74 | + vector_display_begin_draw(display, |
| 75 | + x + radius * sin(edgeangle + angadjust), |
| 76 | + y - radius * cos(edgeangle + angadjust)); |
| 77 | + for (edgeangle = 0; edgeangle < 2 * M_PI - 0.001; edgeangle += step) { |
| 78 | + vector_display_draw_to(display, |
| 79 | + x + radius * sin(edgeangle + step - angadjust), |
| 80 | + y - radius * cos(edgeangle + step - angadjust)); |
| 81 | + } |
| 82 | + vector_display_end_draw(display); |
| 83 | +} |
| 84 | + |
| 85 | +static void draw_box(vector_display_t *display, double x, double y, double w, double h) { |
| 86 | + vector_display_begin_draw(display, x, y); |
| 87 | + vector_display_draw_to(display, x + w, y); |
| 88 | + vector_display_draw_to(display, x + w, y + h); |
| 89 | + vector_display_draw_to(display, x, y + h); |
| 90 | + vector_display_draw_to(display, x, y); |
| 91 | + vector_display_end_draw(display); |
| 92 | +} |
| 93 | + |
| 94 | +void myDisplay() { |
| 95 | + int i, j; |
| 96 | + |
| 97 | + vector_display_clear(display); |
| 98 | + |
| 99 | + // |
| 100 | + // test pattern for simplex font |
| 101 | + // |
| 102 | + //vector_font_simplex_draw(display, 100, 1300, 5.0, "Hello, World!"); |
| 103 | + vector_display_set_color(display, 0.7f, 0.7f, 1.0f); |
| 104 | + vector_font_simplex_draw(display, 50, 180, 3.5, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); |
| 105 | + vector_font_simplex_draw(display, 50, 360, 3.5, "abcdefghijklmnopqrstuvwxyz"); |
| 106 | + vector_font_simplex_draw(display, 50, 540, 3.5, "1234567890"); |
| 107 | + vector_font_simplex_draw(display, 50, 720, 3.5, "!@#$%^&*()-=<>/?;:'\"{}[]|\\+=-_"); |
| 108 | + |
| 109 | + // |
| 110 | + // test pattern for lines |
| 111 | + // |
| 112 | + vector_display_set_color(display, 1.0f, 0.7f, 0.7f); |
| 113 | + for (i = 0; i < 4; i++) { |
| 114 | + for (j = 0; j < i; j++) { |
| 115 | + vector_display_draw(display, 50, 750 + 100 * i, 400, 750 + 100 * i); // draw line |
| 116 | + vector_display_draw(display, 500, 750 + 100 * i, 500, 750 + 100 * i); // draw dot |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + for (i = 0; i < 4; i++) { |
| 121 | + for (j = 0; j <= i; j++) { |
| 122 | + vector_display_draw(display, 50 + 100 * i, 1200, 50 + 100 * i, 1400); // draw line |
| 123 | + vector_display_draw(display, 50 + 100 * i, 1450, 50 + 100 * i, 1450); // draw dot |
| 124 | + } |
| 125 | + } |
| 126 | + |
| 127 | + // |
| 128 | + // test pattern for shapes |
| 129 | + // |
| 130 | + vector_display_set_color(display, 0.7f, 0.7f, 1.0f); |
| 131 | + draw_circle(display, 500, 950, 20, 32); |
| 132 | + draw_circle(display, 600, 950, 50, 32); |
| 133 | + draw_circle(display, 800, 950, 100, 32); |
| 134 | + draw_circle(display, 1075, 950, 150, 64); |
| 135 | + |
| 136 | + vector_display_set_color(display, 0.7f, 1.0f, 0.7f); |
| 137 | + draw_box(display, 500, 1200, 40, 40); |
| 138 | + draw_box(display, 565, 1200, 100, 100); |
| 139 | + draw_box(display, 700, 1200, 200, 200); |
| 140 | + draw_box(display, 950, 1200, 300, 300); |
| 141 | + |
| 142 | + vector_display_set_color(display, 1.0f, 0.7f, 1.0f); |
| 143 | + draw_wheel(display, M_PI, 1425, 950, 150); |
| 144 | + draw_wheel(display, 3 * M_PI / 4, 1700, 950, 100); |
| 145 | + draw_wheel(display, M_PI / 2, 1900, 950, 50); |
| 146 | + draw_wheel(display, M_PI / 4, 2000, 950, 20); |
| 147 | +} |
| 148 | + |
| 149 | +int main (int argc, char **argv) { |
| 150 | + glutInit(&argc,argv); |
| 151 | + glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); |
| 152 | + glutInitWindowSize(1024, 1024); |
| 153 | + glutInitWindowPosition(100,100); |
| 154 | + glutCreateWindow("Vector"); |
| 155 | + |
| 156 | + glutDisplayFunc(myDisplay); |
| 157 | + |
| 158 | + myInit(); |
| 159 | + |
| 160 | + glutMainLoop(); |
| 161 | + |
| 162 | + return 0; |
| 163 | +} |
| 164 | + |
0 commit comments