views:

72

answers:

1

What am I doing wrong here, I can't get the result of this division:

aspectRatio = backingWidth / backingHeight;

I've thought I might try casting to (GLfloat) but that didn't do anything. As I step through the code I see that aspectRatio is 0 after the operation, while backingWidth is clearly 768 and backingHeight is 1029.

Here are the types:

GLfloat aspectRatio;

and

// The pixel dimensions of the CAEAGLLayer
GLint backingWidth;
GLint backingHeight;

It must be something basic I'm doing wrong here..

+2  A: 

You need to cast either of the values to a floating point type, otherwise the division itself is made using integers:

aspectRatio = (GLfloat) backingWidth / backingHeight;
unwind
Lesson learned. I was thinking that these operations automatically "upgraded" the resulting datatype to the largest datatype involved.It works now using: **aspectRatio = (GLfloat) backingWidth / backingHeight;**Thanks!
If it works then you can accept it as answer ?
hib
Yes. I just figured out how to do an accept. Thank you :)