Skip to content

Commit

Permalink
cleanup example
Browse files Browse the repository at this point in the history
  • Loading branch information
micahpearlman committed Feb 21, 2022
1 parent bec0924 commit 8de483c
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions examples/glfw_hello_world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
// System
#include <iostream>

#define WINDOW_WIDTH 1024
#define WINDOW_HEIGHT 768

int main(int argc, char **argv) {
// Initialise GLFW
if (!glfwInit()) {
Expand All @@ -29,18 +32,18 @@ int main(int argc, char **argv) {
// Open a window and create its OpenGL context
GLFWwindow *window; // (In the accompanying source code, this variable is
// global for simplicity)
window = glfwCreateWindow(1024, 768, "MonkVG Hello World", NULL, NULL);
window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "MonkVG Hello World",
NULL, NULL);
if (window == NULL) {
fprintf(
stderr,
"Failed to open GLFW window.\n");
fprintf(stderr, "Failed to open GLFW window.\n");
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window); // Initialize GLEW

// Initialize MonkVG using GLES 2.0 rendering
vgCreateContextMNK(1024, 768, VG_RENDERING_BACKEND_TYPE_OPENGLES20);
vgCreateContextMNK(WINDOW_WIDTH, WINDOW_HEIGHT,
VG_RENDERING_BACKEND_TYPE_OPENGLES20);

// create a paint
VGPaint paint;
Expand All @@ -52,26 +55,37 @@ int main(int argc, char **argv) {

// create a simple box path
VGPath path;
path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0,
0, VG_PATH_CAPABILITY_ALL);
vguRect(path, 150.0f, 150.0f, 190.0f, 150.0f);
path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0,
VG_PATH_CAPABILITY_ALL);
vguRect(path, 0.0f, 0.0f, 100.0f, 150.0f);

// Ensure we can capture the escape key being pressed below
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);

// set viewport
int width, height;
glfwGetFramebufferSize(window, &width, &height);
glViewport(0, 0, width, height);

do {

// Clear the screen.
glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

/// do an ortho camera
// NOTE: this is not standard OpenVG
vgPushOrthoCamera(0.0f, (float)width, (float)height, 0.0f, -1.0f, 1.0f);

/// draw the basic path
vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
vgLoadIdentity();
vgTranslate(1024 / 2, 768 / 2);
vgTranslate(width / 2, height / 2);
vgSetPaint(paint, VG_FILL_PATH);
vgDrawPath(path, VG_FILL_PATH);

vgPopOrthoCamera();

// Swap buffers
glfwSwapBuffers(window);
glfwPollEvents();
Expand All @@ -80,5 +94,12 @@ int main(int argc, char **argv) {
while (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS &&
glfwWindowShouldClose(window) == 0);

// destroy MonkVG
vgDestroyPath(path);
vgDestroyPaint(paint);
vgDestroyContextMNK();

glfwDestroyWindow(window);

return 0;
}

0 comments on commit 8de483c

Please sign in to comment.