Skip to content

Instantly share code, notes, and snippets.

@ebraminio
Last active May 11, 2020 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebraminio/be79a132abf67b351a8490c1c59725b4 to your computer and use it in GitHub Desktop.
Save ebraminio/be79a132abf67b351a8490c1c59725b4 to your computer and use it in GitHub Desktop.
nv path sample
// gcc nvpath.c -o nvpath -lGL -lglfw && primusrun ./nvpath
#include <stdio.h>
#include <stdlib.h>
#include <GLFW/glfw3.h>
#ifndef __APPLE__
PFNGLPATHCOMMANDSNVPROC glPathCommandsNV = NULL;
PFNGLCOVERSTROKEPATHNVPROC glCoverStrokePathNV = NULL;
#endif
#if defined(linux) || defined(sun)
#include <GL/glx.h>
# define GET_PROC_ADDRESS(name) glXGetProcAddressARB((const GLubyte *) #name)
#elif defined(vxworks)
# define GET_PROC_ADDRESS(name) rglGetProcAddress(#name)
#elif defined(__APPLE__)
# define GET_PROC_ADDRESS(name) /*nothing*/
#elif defined(_WIN32)
# define GET_PROC_ADDRESS(name) wglGetProcAddress(#name)
#else
# error unimplemented code!
#endif
#ifdef __APPLE__
#define LOAD_PROC(type, name) /*nothing*/
#else
#define LOAD_PROC(type, name) name = (type) GET_PROC_ADDRESS(name); if (!name) exit(1);
#endif
int
main(int argc, char **argv)
{
if (!glfwInit()) return -1;
GLFWwindow *window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window) {
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
// Load extensions
LOAD_PROC(PFNGLPATHCOMMANDSNVPROC, glPathCommandsNV);
LOAD_PROC(PFNGLCOVERSTROKEPATHNVPROC, glCoverStrokePathNV);
// Init a path
GLubyte pathCommands[5] =
{ GL_MOVE_TO_NV, GL_LINE_TO_NV, GL_LINE_TO_NV, GL_LINE_TO_NV, GL_CLOSE_PATH_NV };
GLfloat pathCoords[4][2] = { {.1, .1}, {.3, .1}, {.3, .3}, {.1, .3} };
GLuint pathObj = 42;
glPathCommandsNV(pathObj, 5, pathCommands, 8, GL_FLOAT, pathCoords);
while (!glfwWindowShouldClose(window)) {
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glClearColor(0, 0, 0, 0);
glStencilMask(~0);
glCoverStrokePathNV(pathObj, GL_CONVEX_HULL_NV);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment