View All Posts
read
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi
#3D RENDERING #CODING TUTORIAL #ES20 #OPENGL #PROGRAM PORTING

There’s actually nothing specific to ES2.0 in this port - the code is exactly the same as in tutorial 3, but we are now passing all the data required to draw 3D shapes.

There are a couple of gotchas - for some reason in the default OpenGL template that xCode gives you does not have a depth buffer. So we need to add that to the initialisation in EAGLView.m

  glGenRenderbuffers(1, &depthbuffer);
  glBindRenderbuffer(GL_RENDERBUFFER, depthbuffer);
  glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24_OES, framebufferWidth, framebufferHeight);
  glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthbuffer);    

The other interesting thing in this project is that I’ve added rotation to the objects. This requires saving the model view matrix so we can rotate the objects individually. So in the code we now have:

 // reset our modelview to identity
 esMatrixLoadIdentity(&modelView);
 // translate back into the screen by 6 units and down by 1 unit
 esTranslate(&modelView, 0.0f , -1.0f, -6.0f);
 // save the current modelView
 ESMatrix savedModelView=modelView;
 // rotate the triangle
 esRotate(&modelView, rPyramid, 0.0, 1.0, 0.0);
 // tell the GPU we want to use our program
 glUseProgram(simpleProgram);
 // create our new mvp matrix
 esMatrixMultiply(&mvp, &modelView, &projection );
 // set the mvp uniform
 glUniformMatrix4fv(uniformMvp, 1, GL_FALSE, (GLfloat*) &mvp.m[0][0] );
  
  
 ... do the drawing of the pyramid

 // now draw a cube
  
 // translate up by 3 units
 esTranslate(&savedModelView, 0.0f , 3.0f, 0.0f);
 // rotate by 45 degrees around the z axis
 esRotate(&savedModelView, rCube, 0.0, 0.0, 1.0f);
 // create our new mvp matrix
 esMatrixMultiply(&mvp, &savedModelView, &projection );
 // update the mvp uniform
 glUniformMatrix4fv(uniformMvp, 1, GL_FALSE, (GLfloat*) &mvp.m[0][0] );

 ... do the drawing of the cube

We can save our matix pretty easily by just assigning it to another instance of the ESMatrix struct - this will copy all the values across so we can take a snapshot of it.

If you want to get clever you can re-implement the push and pop matrix functionality using std::stack.

Tutorial 5 is available here.

#3D RENDERING #CODING TUTORIAL #ES20 #OPENGL #PROGRAM PORTING

Related Posts

NeHe OpenGL tutorial 2, 3 and 4 ported to ES 2.0 - As I strove to learn OpenGLES 2.0 for new gaming projects on iPhone and Palm Pre, I faced certain challenges due to the introduction of a programmable graphics pipeline in OpenGLES 2.0. With this mechanism, we are responsible for writing the code to generate our graphics, which was overwhelming at first. To help others, I ported some of the NeHe tutorials over to OpenGLES2.0 on iPhone in an easily-digestible way. In this post, you will find a walkthrough of the first 4 tutorials, complete with codes, explanations and screenshots to make learning easier.
NeHe OpenGL tutorial 6 ported to ES2.0 - This tutorial guides you through applying textures to a rotating 3D cube using OpenGL. We will be utilizing the esUtils code, specifically its function esGenCube, and modify our shaders to accommodate our texture coordinates. After setting up our new mvp matrix and position vertex attribute, we will apply a texture to our rotating cube. The code can be found via a provided link.
Getting started with Box2D - Just gave a enlightening talk on Box2D at the LiDG and have prepared a step-by-step walkthrough on creating a simple pinball game using the open sourced 2D physics engine! You'll learn the concepts of Body, Shape, Friction, etc. as well as how to build and run the Box2D engine for iPhone. By the end of the blog, you'll be equipped to create a basic working game in a couple of 100 lines of code! Don't forget to check out my slides and demos linked in the blog!
Creating an OpenGL game for both the Palm and iOS - I've made a triumphant return to the blogosphere with the release of my new game, 'Tanks!' developed for Palm Pre/Pixie and soon for iPhone devices. The game, an experiment to learn OpenGLES 2.0, is a testament to the feasibility of porting C++ or C code from iOS to Palm PDK, despite minor challenges with UI interaction and audio. So gear up, folks! Download 'Tanks!', step onto the battlefield and let the mayhem begin! Next stop on my coding odyssey - Android!

Related Videos

AR Sudoku Solver in Your Browser: TensorFlow & Image Processing Magic - Discover how to recreate a Sudoku app using browser APIs and ecosystem advancements, and explore the image processing pipeline technique for extracting Sudoku puzzles and solving them.
Laser Projected Asteroids: ESP32 Reinvents Classic Arcade Game! - Learn how to create a classic Arduino ESP32 Asteroids game with laser projection, including a tour of the system hardware and a look at its firmware and game engine. Watch a demonstration and comparison of fonts, as well as an overview of the audio output. Dive into the schematics and try out the game for yourself!
Fusion 360 Spherical Texture Mapping - Learn how to map a 2D texture onto a sphere in Fusion 360, using spherical projection and adjusting texture scales to create stunning images like Mars and the Moon.
ESP32-S3 - Which Pins Are Safe To Use? - In this video, I've decided to dive deep into the ESP32-S3, a module ruling my lab recently due to its plug-in-and-play functionality, and the flexibility offered by its GPIO matrix. However, working with it requires vigilance, especially with regard to the strapping pins and USB data pins, among others. Discovering such quirks, I've encountered unexpected values, short glitches and the occasional code crash. To help you avoid these bumps, I've documented everything I've learned on my GitHub repo, where I'm inviting you, my fellow makers and engineers, to contribute your valuable experiences and findings. After a minor hiccup with my ESP32-TV, expect an updated PCB design, courtesy of PCBWay. Explore the ESP32-S3 with me, and let's unravel its secrets together, one pull request at a time.
256 Shades of Grey – Adventures in Image Processing - In this enlightening video, I delve into the deep and fascinating world of image processing. Forget everything you thought you knew about pixels – they’re not squares or rectangles and they definitely aren’t discs. All pixels are, my friends, are point samples, each capturing brightness or color at a particular position. Curious to know how to manipulate them? I also unravel this mysterious tapestry, familiarizing you with the technicalities of grayscale, RGB, HSB, YUV, and a fleeting mention of CMYK. And if you think that's all, hold tight! Did you know we could apply Fourier transforms, akin to graphic equalisers used in audio, to our good old two-dimensional images? Strap in as I guide you through this potentially overwhelming realm with a pinch of humor, lots of simplicity, and oodles of practical examples.
HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
Blog Logo

Chris Greening


Published

> Image

atomic14

A collection of slightly mad projects, instructive/educational videos, and generally interesting stuff. Building projects around the Arduino and ESP32 platforms - we'll be exploring AI, Computer Vision, Audio, 3D Printing - it may get a bit eclectic...

View All Posts