Hey folks. I’ve been coding in OpenGL for a few days using python (and a library, pygame, to handle input and drawing), and I’m struggling to wrap my head around it.
-
My first question is about glLoadIdentity(). My current understanding is this: There is an origin, (0,0,0), that the program starts at. If you use glTranslate or glRotate then you move the current location; say, if you translate (0,1,0), then the new current location is 1 tile above the origin. Now, if you draw a vertex at location (0,0,0), it will draw relative to this new coordinate. Then if you use glLoadIdentity(), the current coordinate moves back to the origin again; so if you draw another vertex, it will be relative to (0,0,0). Is this correct?
-
I’m a bit confused as to when I should use it. Should I use it at the start of the frame, and have every object draw relative to it? Should every single object’s render function use it to translate to the center, translate by its location and then draw?
-
Also, if anybody is feeling generous, could you write me some really quick pseudocode for a program that draws a plane in a fixed location, allows the camera to move about and draws a cube in front of the camera.
My current code looks like this:
rotate and move camera based on input
glLoadIdentity()
rotate the camera on the x plane
prot.render(camera.position) # prot is the cube in front of the camera
rotate the camera on the y plane
plane.render() # Just a random plane so that I know the cube is moving relative to stationary objects.
Any help? I’ve browsed tutorials but they aren’t so specific so please don’t just link me to the red book or anything.