draw.h
#include<QtOpenGL>
#include<QString>
{
public:
Draw(void);
protected:
void initializeGL();
void paintGL();
void resizeGL(int width,int height);
}
draw.cpp
#include "draw.h"
void NgiDrawWiggle::initializeGL()//called firstly
{
z=(this->h/2)/(tan((45.0/2.0)*(3.1415926/180.0)))+0.5;
glShadeModel( GL_SMOOTH );
glClearColor( 1.0, 1.0, 1.0, 0.0 );
glClearDepth( 1.0 );
glDisable( GL_DEPTH_TEST );
// glDepthFunc( GL_LEQUAL );
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
}
void NgiDrawWiggle::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3ub(0,10,250);
drawText("Time",-65,(50-7*h)/20.0);
}
void NgiDrawWiggle::resizeGL(int width,int height)
{
if ( height == 0 )
{
height = 1;
}
glViewport( 0, 0, (GLint)width, (GLint)height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 45.0, (GLfloat)width/(GLfloat)height, 0.1, 1000 );//
glMatrixMode( GL_MODELVIEW );
}
void Draw
::drawText(QString str,
int x,
int y
) {
glLoadIdentity();
glTranslatef(30.0,30.0,-z);//"z" is the depth of the scene through the "z=(this->h/2)/(tan((45.0/2.0)*(3.1415926/180.0)))+0.5","h" is the height of the scene.
glRotatef(90,0,0,1);
renderText(x,y,0,str);
}
draw.h
#include<QtOpenGL>
#include<QString>
class Draw:public QGLWidget
{
public:
Draw(QWidget* parent=0);
Draw(void);
void drawText(QString,int,int);
protected:
void initializeGL();
void paintGL();
void resizeGL(int width,int height);
}
draw.cpp
#include "draw.h"
void NgiDrawWiggle::initializeGL()//called firstly
{
z=(this->h/2)/(tan((45.0/2.0)*(3.1415926/180.0)))+0.5;
glShadeModel( GL_SMOOTH );
glClearColor( 1.0, 1.0, 1.0, 0.0 );
glClearDepth( 1.0 );
glDisable( GL_DEPTH_TEST );
// glDepthFunc( GL_LEQUAL );
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
}
void NgiDrawWiggle::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3ub(0,10,250);
drawText("Time",-65,(50-7*h)/20.0);
}
void NgiDrawWiggle::resizeGL(int width,int height)
{
if ( height == 0 )
{
height = 1;
}
glViewport( 0, 0, (GLint)width, (GLint)height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 45.0, (GLfloat)width/(GLfloat)height, 0.1, 1000 );//
glMatrixMode( GL_MODELVIEW );
}
void Draw::drawText(QString str,int x,int y)
{
glLoadIdentity();
glTranslatef(30.0,30.0,-z);//"z" is the depth of the scene through the "z=(this->h/2)/(tan((45.0/2.0)*(3.1415926/180.0)))+0.5","h" is the height of the scene.
glRotatef(90,0,0,1);
renderText(x,y,0,str);
}
To copy to clipboard, switch view to plain text mode
I really don't know what I should do in the drawText(),thanks for your helping. Would you please give the complete debugged code?By the way, can I use "show list" in which renderText() is included?
Bookmarks