Created
November 30, 2012 12:02
-
-
Save dannycalleri/4175381 to your computer and use it in GitHub Desktop.
Danny Calleri's version of NeHe's iOS OpenGL Lesson02
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "Lesson02.h" | |
| #import <OpenGLES/ES2/gl.h> | |
| #import <OpenGLES/ES2/glext.h> | |
| #include <vector> | |
| Lesson02::Lesson02() | |
| : shader(NULL), | |
| texture(NULL), | |
| sprite(NULL) | |
| { | |
| } | |
| //lesson destructor | |
| Lesson02::~Lesson02() | |
| { | |
| delete sprite; | |
| delete shader; | |
| delete texture; | |
| } | |
| //initializing all OpenGL related things | |
| void Lesson02::init() | |
| { | |
| printf("Init.."); | |
| //set the color we use for clearing our colorRenderbuffer to black | |
| glClearColor(0.3, 0.3, 0.3, 1.0); | |
| glEnable(GL_CULL_FACE); | |
| glEnable(GL_TEXTURE_2D); | |
| //loading the texture | |
| texture = new Texture(); | |
| texture->loadPNG("background.png"); | |
| //--------------------------------------------------- | |
| //load our shader | |
| shader = new Shader("sprite_shader.vert", "sprite_shader.frag"); | |
| if(!shader->compileAndLink()) | |
| { | |
| printf("Encountered problems when loading shader, application will crash..."); | |
| } | |
| sprite = new Sprite(texture, shader, 30, 30); | |
| //tell OpenGL to use this shader for all coming rendering | |
| glUseProgram(shader->getProgram()); | |
| printf("Init done..."); | |
| printf("\nBUFFER WIDTH : %d\n", m_renderbufferWidth); | |
| printf("\nBUFFER HEIGHT : %d\n", m_renderbufferHeight); | |
| } | |
| //drawing a frame | |
| void Lesson02::draw() | |
| { | |
| //clear the color buffer | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| sprite->render(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment