Qt and OpenGL Primitives in mobile resolution
-
wrote on 25 May 2011, 12:31 last edited by
Hi...
I'm new to OpenGL in Qt..
and I've been trying to draw points in screen corners... I'm using Nokia 900 simulator
by default the co-ordinate range in openGL is
X: -1 to 1
Y: -1 to 1right?
But here in mobile resolution it changes and couldn't predict the change ratio....
how to solve this...?
I've set the ViewPort width and height to 360 and 640.
-
wrote on 25 May 2011, 13:39 last edited by
Please post some compilable code that reproduces your problem.
-
wrote on 25 May 2011, 13:43 last edited by
This is the OpenGL code..
@#include "gameplay.h"
GamePlay::GamePlay(QWidget *parent) :
QGLWidget(parent)
{
setFormat(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer));
rotationX = -21.0;
rotationY = -57.0;
rotationZ = 0.0;
faceColors[0] = Qt::red;
faceColors[1] = Qt::green;
faceColors[2] = Qt::blue;
faceColors[3] = Qt::yellow;
}void GamePlay::initializeGL()
{
qglClearColor(Qt::green);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
}void GamePlay::resizeGL(int width,int height)
{
width=360;
height=640;
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
GLfloat x = GLfloat(width) / height;glFrustum(-x, x, -1, 1, 2.0, 15); glMatrixMode(GL_MODELVIEW);
}
void GamePlay::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
draw();
}void GamePlay::draw()
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0, -10);glPointSize(4.0); glBegin(GL_POINTS); glVertex3f(0,0,0); glEnd();
}
@
The draw function should draw a point of size 4 at the center of the screen.... right?
I does draw a point but not in the Center of the screen(orgin).
-
wrote on 25 May 2011, 20:44 last edited by
Please try setting projection matrix with gluPerspective.
-
wrote on 26 May 2011, 05:11 last edited by
No... I have tried that too... same effect...
-
wrote on 26 May 2011, 05:36 last edited by
Is this because of the simulator banner added by the QT in the output in simulator?
-
wrote on 26 May 2011, 09:41 last edited by
What were the parameters for gluPerspective?
1/7