I've been unable to figure this out on my own.
I currently have an Open GLES setup where a view controller both updates a game world (with a dt), fetches the data I need to render, passes it off to an EAGLView through two structures (built of Apple's ES1Renderer), and draws the scene.
Whenever a value originates outside of the Open GL view, it can't be used to either translate objects using glTranslatef, or set up the scene using glOrthof. If I assign a new value to something, it will work - even if it is the exact same number.
The two structures I have each contain a variety of floating-point numbers and booleans, along with two arrays. I can log the values from within my renderer - they make it there - but I receive errors from OpenGL if I try to do anything with them. No crashes result, but the glOrthof call doesn't work if I don't set the camera values to anything different.
Code used to set up scene:
[EAGLContext setCurrentContext:context];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
//clears the color buffer bit
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
//sets up the scene w/ ortho projection
glViewport(0, 0, 320, 480);
glLoadIdentity();
glOrthof(320, 0, dynamicData.cam_x2, dynamicData.cam_x1, 1.0, -1.0);
glClearColor(1.0, 1.0, 1.0, 1.0);
/*error checking code here*/
"dynamicData" (which is replaced every frame) is created within my game simulation. From within my controller, I call a method (w/in my simulation) that returns it, and pass the result on to the EAGLView, which passes it on to the renderer. I haven't been able to come up with a better solution for this - suggestions in this regard would be greatly appreciated as well.
Also, this function doesn't work as well (values originate in the same place):
glTranslatef(dynamicData.ship_x, dynamicData.ship_y, 0.0);
Thanks in advance.
Additional Definitions:
Structure (declared in a separate header):
typedef struct {
float ship_x, ship_y;
float cam_x1, cam_x2;
} dynamicRenderData;
Render data getter (and builder) (every frame)
- (dynamicRenderData)getDynRenderData
{
//d_rd is an ivar, zeroed on initialization
d_rd.ship_x = mainShip.position.x;
d_rd.ship_y = mainShip.position.y;
d_rd.cam_x1 = d_rd.ship_x - 30.0f;
d_rd.cam_x2 = d_rd.cam_x1 + 480.0f;
return d_rd;
}
Zeroed at start. (d_rd.ship_x = 0;
, etc…)
Setting up the view.
Prototype (GLView): - (void)draw: (dynamicRenderData)dynamicData
Prototype (Renderer): - (void)drawView: (dynamicRenderData)dynamicData
How it's called w/in the controller:
//controller
[glview draw: [world getDynRenderData]];
//glview (within draw)
[renderer drawView: dynamicData];