views:

54

answers:

0

Hello everyone.

I would like to say that my OpenGL-ES experience is very limited and that I've been searching for an answer without success.

I'm trying to draw a textured plane with the following code

const GLfloat spriteVertices[] = {
        -1.0f, -1.5f,
         1.0f, -1.5f,
        -1.0f,  1.5f,
         1.0f,  1.5f,
    };

glVertexPointer(2, GL_FLOAT, 0, spriteVertices);
glEnableClientState(GL_VERTEX_ARRAY);

And it does draw. However, I would like to be able to draw this plane depending on a given height and width. So I tough... let's try this:

CGFloat proportionX, proportionY;

if (width > height) {
    proportionX = 1.0f;
    proportionY = (height * 1.0f) / width;
}
else if (width < height){
    proportionX = (width * 1.5f) / height;
    proportionY = 1.5f;
}
else {
    proportionX = 1.0f;
    proportionY = 1.0f;
}

const GLfloat spriteVertices[] = {
    -proportionX, -proportionY,
    proportionX, -proportionY,
    -proportionX,  proportionY,
    proportionX,  proportionY,
};

All it does is return a value between 0 and 1 for width and a value between 0 and 1.5 for height. This because the iPhone screen is 320 by 480 [1 by 1.5]. The problem is that it simply wont draw my plane..

Pictures may explain better than my bad English hehe.

http://img541.imageshack.us/img541/4278/ss1mp.png

On the left draws but non-proportional On the right draws nothing trying to set proportion

[can't add images yet as I don't have enough user points =P]

Any help will be deeply appreciated. Thanks