Coder Social home page Coder Social logo

glbind's Introduction

A single file OpenGL header and API loader.

discord mastodon

glbind includes a full implementation of the OpenGL headers (auto-generated from the OpenGL spec) so there's no need for the offical headers or SDK. Unlike the official headers, the platform-specific sections are all contained within the same file.

Usage

glbind is a single file library with no dependencies. There's no need to link to any libraries, nor do you need to include any other headers. Everything you need is included in glbind.h.

#define GLBIND_IMPLEMENTATION
#include "glbind.h"

int main()
{
    GLenum result = glbInit(NULL, NULL);
    if (result != GL_NO_ERROR) {
        printf("Failed to initialize glbind.");
        return -1;
    }
    
    ...
    
    glClearColor(0, 0, 0, 0);
    glClear(GL_COLOR_BUFFER_BIT);

    ...

    glbUninit();
    return 0;
}

The example above binds everything to global scope and uses default settings for the internal rendering context. You can also initialize glbind like the code below.

GLBapi gl;
GLBconfig config = glbConfigInit();
config.singleBuffered = GL_TRUE;    /* Don't use double-buffering on the internal rendering context. */
GLenum result = glbInit(&gl, &config);
if (result != GL_NO_ERROR) {
    ... error initializing glbind ...
}

#if defined(GLBIND_WGL)
HGLRC hRC = glbGetRC();
... do something with hRC ...
#endif

#if defined(GLBIND_GLX)
GLXContext rc = glbGetRC();
... do something with rc ...
#endif

/* Draw something using local function pointers in the "gl" object instead of global scope. */
gl.glClearColor(0, 0, 0, 0);
gl.glClear(GL_COLOR_BUFFER_BIT);

Since OpenGL requires a rendering context in order to retrieve function pointers, it makes sense to give the client access to it so they can avoid wasting time and memory creating their own rendering context unnecessarily. Therefore, glbind allows you to configure the internal rendering context and retrieve a handle to it so the application can make use of it.

You can also initialize a GLBapi object against the current context (previously set with wglMakeCurrent or glXMakeCurrent) using glbInitContextAPI() or glbInitCurrentContextAPI(). Note, however, that before calling these functions you must have previously called glbInit(). These also do not automatically bind anything to global scope.

You can explicitly bind the function pointers in a GLBapi object to global scope by using glbBindAPI().

License

Public domain or MIT-0 (No Attribution). Choose whichever you prefer.

glbind's People

Contributors

mackron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

glbind's Issues

Building glbind.h on Windows through MinGW mixes CRLF lines with LF lines

Since glbOpenAndReadFileWithExtraData uses "rb" mode to open files, on Windows they will retain their CR (\r).

result = glbFOpen(filePath, "rb", &pFile);

This causes a problem, because despite tinyxml2 also opening the (.xml) file in "rb" mode
FILE* fp = callfopen( filename, "rb" );

they strip the CR's before parsing
if ( (_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == CR ) {
// CR-LF pair becomes LF
// CR alone becomes LF
// LF-CR becomes LF
if ( *(p+1) == LF ) {
p += 2;
}
else {
++p;
}
*q = LF;
++q;
}

So, when the tags in the template file are replaced

glbind/source/glbind_build.cpp

Lines 1698 to 1706 in bb63d02

for (size_t iTag = 0; iTag < sizeof(tags)/sizeof(tags[0]); ++iTag) {
std::string generatedCode;
result = glbBuildGenerateCode_C(context, tags[iTag], generatedCode);
if (result != GLB_SUCCESS) {
return result;
}
glbReplaceAllInline(outputStr, tags[iTag], generatedCode);
}

they have only LF line endings.

You can check this is the case by compiling and running the build code with MinGW.
Checking with git:

glbind $ git ls-files --eol
i/lf    w/crlf  attr/                   .gitignore
i/lf    w/crlf  attr/                   README.md
i/lf    w/crlf  attr/                   build/README.md
i/lf    w/crlf  attr/                   examples/01_Triangle/01_Triangle.c
i/lf    w/crlf  attr/                   examples/99_ARB_shaders/99_ARB_shaders.c
i/lf    w/crlf  attr/                   examples/99_ARB_shaders/resources/FragmentShader.txt
i/lf    w/crlf  attr/                   examples/99_ARB_shaders/resources/VertexShader.txt
i/lf    w/crlf  attr/                   examples/glbExamplesCommon.c
i/lf    w/mixed attr/                   glbind.h
i/lf    w/crlf  attr/                   resources/README.md
i/lf    w/crlf  attr/                   source/external/tinyxml2.cpp
i/lf    w/crlf  attr/                   source/external/tinyxml2.h
i/lf    w/crlf  attr/                   source/glbind_build.cpp
i/lf    w/crlf  attr/                   source/glbind_template.h

I made a fix by stripping the CR's #1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.