https://github.com/haraldbregu/shader-wrapper
C++ Shader Wrapper for Opengl ES
https://github.com/haraldbregu/shader-wrapper
Last synced: about 2 months ago
JSON representation
C++ Shader Wrapper for Opengl ES
- Host: GitHub
- URL: https://github.com/haraldbregu/shader-wrapper
- Owner: HaraldBregu
- License: mit
- Created: 2014-02-23T14:07:57.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2014-02-23T15:40:53.000Z (about 11 years ago)
- Last Synced: 2025-01-14T04:14:19.647Z (3 months ago)
- Language: C++
- Homepage:
- Size: 145 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Shader-Wrapper
==============C++ Shader class to use in all platforms
1. Ceate vsh and fsh files (if not created yet)
2. Edit "glShaderHeader.h" for attributes and uniforms
3. Add "glShaderHeader.h" to your implementation class
4. Load sources of vertex and fragment shader
5. Create an instance of shader class "glShaderWrapper.h" and use it### Load files in objective-c
NSString *vshPath = [[NSBundle mainBundle] pathForResource:@"template" ofType:@"vsh"];
const char *vshSource = [[NSString stringWithContentsOfFile:vshPath encoding:NSUTF8StringEncoding error:nil] UTF8String];
NSString *fshPath = [[NSBundle mainBundle] pathForResource:@"template" ofType:@"fsh"];
const char *fshSource = [[NSString stringWithContentsOfFile:fshPath encoding :NSUTF8StringEncoding error:nil] UTF8String];### Load shader
glShaderWrapper loadShader = glShaderWrapper(vshSource, fshSource);
loadShader.bindAttributeLocation(ATTRIB_VERTEX, "position"); // 1
loadShader.bindAttributeLocation(ATTRIB_COLOR, "color"); // 1
loadShader.link(); // Link shaderGLuint position = loadShader.attributeLocation("position"); // Optional get attribute location
GLuint color = loadShader.attributeLocation("color"); // Optional get attribute locationuniforms[U_MV_PROJ_MTX] = loadShader.uniformLocation("modelViewProjectionMatrix"); // Get uniform location
loadShader.use(); // Use shader
###FAST IMPLEMENTATION
Copy and pasteinclude "glShaderHeader.h"
NSString *vshPath = [[NSBundle mainBundle] pathForResource:@"template" ofType:@"vsh"];
const char *vshSource = [[NSString stringWithContentsOfFile:vshPath encoding:NSUTF8StringEncoding error:nil] UTF8String];
NSString *fshPath = [[NSBundle mainBundle] pathForResource:@"template" ofType:@"fsh"];
const char *fshSource = [[NSString stringWithContentsOfFile:fshPath encoding:NSUTF8StringEncoding error:nil] UTF8String];
//LOAD SHADER
glShaderWrapper loadShader = glShaderWrapper(vshSource, fshSource);
loadShader.bindAttributeLocation(ATTRIB_VERTEX, "position");
loadShader.bindAttributeLocation(ATTRIB_COLOR, "color");
loadShader.link();
GLuint position = loadShader.attributeLocation("position"); //Optional
GLuint color = loadShader.attributeLocation("color"); //Optional
uniforms[U_MV_PROJ_MTX] = loadShader.uniformLocation("modelViewProjectionMatrix");
loadShader.use();