Top Banner

Click here to load reader

OpenGL on iOS & OSX - Nathanael · PDF fileOpenGL on iOS & OSX Low-level GL, SceneKit, and GLSL Shaders. OpenGL. OpenGL • OpenGL and GLKit bundled with Xcode. OpenGL

Mar 01, 2018

ReportDownload

Documents

vocong

  • OpenGL on iOS & OSXLow-level GL, SceneKit, and GLSL Shaders

  • OpenGL

  • OpenGL

    OpenGL and GLKit bundled with Xcode

  • OpenGL

    OpenGL and GLKit bundled with Xcode GLView and GLViewController available

  • OpenGL

    OpenGL and GLKit bundled with Xcode GLView and GLViewController available

    Works like any other views

  • OpenGL

    OpenGL and GLKit bundled with Xcode GLView and GLViewController available

    Works like any other views Gestures easily added

  • OpenGL

    OpenGL and GLKit bundled with Xcode GLView and GLViewController available

    Works like any other views Gestures easily added GLView manages frame rate, frame,

    coordinates, rotation

  • OpenGL

  • OpenGL

    GLView

  • OpenGL

    GLView

    GLViewController

  • OpenGL

    GLView

    GLViewController

    GLKView

  • OpenGL

    GLView

    GLViewController

    GLKView

    -(void)glkView:(GLKView *)view drawInRect:(CGRect)rect

  • OpenGL

    GLView

    GLViewController

    UIButton

    GLKView

    -(void)glkView:(GLKView *)view drawInRect:(CGRect)rect

  • OpenGL

    GLView

    GLViewController

    UIButton

    GLKViewOutlet / Action

    -(void)glkView:(GLKView *)view drawInRect:(CGRect)rect

  • OpenGL

    GLView

    GLViewController

    UIButton

    GLKViewOutlet / Action

    -(void)glkView:(GLKView *)view drawInRect:(CGRect)rect

    - (IBAction)toggleAnimation

  • OpenGL

    GLViewController

    GLKViewOutlet / Action

    self.preferredFramesPerSecond = 60; // Start context and initialize color EAGLContext *context = [[EAGLContext alloc]

    initWithAPI:kEAGLRenderingAPIOpenGLES3]; [EAGLContext setCurrentContext:context]; GLKView *glkView = (GLKView *)self.view; glkView.context = context;

  • glClearColor(0.95f, 0.95f, 0.95f, 1.0f); glEnable(GL_CULL_FACE);

    OpenGL

    GLViewController

    GLKViewOutlet / Action

    self.preferredFramesPerSecond = 60; // Start context and initialize color EAGLContext *context = [[EAGLContext alloc]

    initWithAPI:kEAGLRenderingAPIOpenGLES3]; [EAGLContext setCurrentContext:context]; GLKView *glkView = (GLKView *)self.view; glkView.context = context;

  • glClearColor(0.95f, 0.95f, 0.95f, 1.0f); glEnable(GL_CULL_FACE);

    OpenGL

    GLViewController

    GLKViewOutlet / Action

    self.preferredFramesPerSecond = 60; // Start context and initialize color EAGLContext *context = [[EAGLContext alloc]

    initWithAPI:kEAGLRenderingAPIOpenGLES3]; [EAGLContext setCurrentContext:context]; GLKView *glkView = (GLKView *)self.view; glkView.context = context;

  • glClearColor(0.95f, 0.95f, 0.95f, 1.0f); glEnable(GL_CULL_FACE);

    OpenGL

    GLViewController

    GLKViewOutlet / Action

    self.preferredFramesPerSecond = 60; // Start context and initialize color EAGLContext *context = [[EAGLContext alloc]

    initWithAPI:kEAGLRenderingAPIOpenGLES3]; [EAGLContext setCurrentContext:context]; GLKView *glkView = (GLKView *)self.view; glkView.context = context;

  • glClearColor(0.95f, 0.95f, 0.95f, 1.0f); glEnable(GL_CULL_FACE);

    OpenGL

    GLViewController

    GLKViewOutlet / Action

    self.preferredFramesPerSecond = 60; // Start context and initialize color EAGLContext *context = [[EAGLContext alloc]

    initWithAPI:kEAGLRenderingAPIOpenGLES3]; [EAGLContext setCurrentContext:context]; GLKView *glkView = (GLKView *)self.view; glkView.context = context;

  • glClearColor(0.95f, 0.95f, 0.95f, 1.0f); glEnable(GL_CULL_FACE);

    OpenGL

    GLViewController

    GLKViewOutlet / Action

    self.preferredFramesPerSecond = 60; // Start context and initialize color EAGLContext *context = [[EAGLContext alloc]

    initWithAPI:kEAGLRenderingAPIOpenGLES3]; [EAGLContext setCurrentContext:context]; GLKView *glkView = (GLKView *)self.view; glkView.context = context;

  • Still Low Level

  • Still Low Level

    GLKit like glu.hadds utility but little else

  • Still Low Level

    GLKit like glu.hadds utility but little else GLKBaseEffect to emulate GL v1

  • Still Low Level

    GLKit like glu.hadds utility but little else GLKBaseEffect to emulate GL v1

    self.effect = [[GLKBaseEffect alloc] init]; [self.effect prepareToDraw];

  • Still Low Level

    GLKit like glu.hadds utility but little else GLKBaseEffect to emulate GL v1

    self.effect = [[[self

    Lighting similar to Beads in Final Exam

  • Still Low Level

    GLKit like glu.hadds utility but little else GLKBaseEffect to emulate GL v1

    self.effect = [[[self

    Lighting similar to Beads in Final Exam self.effect.light0.enabled = GL_TRUE;

    self.effect.light0.position = GLKVector4Make(1.0f, 1.0f, 1.0f, 1.0f); self.effect.lightingType = GLKLightingTypePerPixel;// Boost light intensity self.effect.light0.constantAttenuation = 0.7;

  • Still Low Level

    GLKit like glu.hadds utility but little else GLKBaseEffect to emulate GL v1

    self.effect = [[[self

    Lighting similar to Beads in Final Exam self.

    self. GLKVector4Makeself.// Boost light intensityself.

    This is still way simpler than GL v2+

  • You are responsible for

  • You are responsible for Binding all Buffers with vertex data (also normals, textures)

    glGenBuffers(1, &_vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(gCubeVertexData), gCubeVertexData, GL_STATIC_DRAW); glEnableVertexAttribArray(GLKVertexAttribPosition); glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(0)); glEnableVertexAttribArray(GLKVertexAttribNormal); glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(12));

  • You are responsible for Binding all Buffers with vertex data (also normals, textures) Set up shader variables including

    glGenBuffers(1, &_vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(gCubeVertexData), gCubeVertexData, GL_STATIC_DRAW); glEnableVertexAttribArray(GLKVertexAttribPosition); glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(0)); glEnableVertexAttribArray(GLKVertexAttribNormal); glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(12));

  • You are responsible for Binding all Buffers with vertex data (also normals, textures) Set up shader variables including

    Projection Matrix

    glGenBuffers(1, &_vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(gCubeVertexData), gCubeVertexData, GL_STATIC_DRAW); glEnableVertexAttribArray(GLKVertexAttribPosition); glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(0)); glEnableVertexAttribArray(GLKVertexAttribNormal); glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(12));

    float aspect = fabsf(self.view.bounds.size.width / self.view.bounds.size.height); GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(65.0f),

    aspect, 0.1f, 100.0f); self.effect.transform.projectionMatrix = projectionMatrix;

  • You are responsible for Binding all Buffers with vertex data (also normals, textures) Set up shader variables including

    Projection Matrix ModelView Matrix

    glGenBuffers(1, &_vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(gCubeVertexData), gCubeVertexData, GL_STATIC_DRAW); glEnableVertexAttribArray(GLKVertexAttribPosition); glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(0)); glEnableVertexAttribArray(GLKVertexAttribNormal); glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(12));

    float aspect = fabsf(self.view.bounds.size.width / self.view.bounds.size.height); GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(65.0f),

    aspect, 0.1f, 100.0f); self.effect.transform.projectionMatrix = projectionMatrix;

    GLKMatrix4 baseModelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, -4.0f); baseModelViewMatrix = GLKMatrix4Rotate(baseModelViewMatrix, _rotation, 0.0f, 1.0f, 0.0f); // Compute the model view matrix for the object rendered with GLKit GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, -1.5f); modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, _rotation, 1.0f, 1.0f, 1.0f); modelViewMatrix = GLKMatrix4Multiply(baseModelViewMatrix, modelViewMatrix);

    self.effect.transform.modelviewMatrix = modelViewMatrix;

  • You are responsible for Binding all Buffers with vertex data (also normals, textures) Set up shader variables including

    Projection Matrix ModelView Matrix Whatever else you want to use in the shader

    glGenBuffers(1, &_vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(gCubeVertexData), gCubeVertexData, GL_STATIC_DRAW); glEnableVertexAttribArray(GLKVertexAttribPosition); glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(0)); glEnableVertexAttribArray(GLKVertexAttribNormal); glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(12));

    float aspect = fabsf(self.view.bounds.size.width / self.view.bounds.size.height); GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(65

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.