Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6043047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:51:24+00:00 2026-05-23T06:51:24+00:00

I am trying to learn||Code openGL in Qt. I made one application which shows

  • 0

I am trying to learn||Code openGL in Qt. I made one application which shows two figures. One is a triangle “A”, and the other triangle “B” is just the same as “A” except it got rotated -90 degree about the z-Axis(z axis is perpendicular to the computer screen). Now, the problem is rotation makes the change in the dimension. I am posting the “main.cpp” below,

#include <QApplication>
#include <QHBoxLayout>
#include <QMessageBox>
#include <QtOpenGL/QGLWidget>
#include <QWidget>

class MyOpenGL:public QGLWidget
{
public:
    MyOpenGL(QWidget * parent);
    ~MyOpenGL();
    void initializeGL();
    void resizeGL(int w, int h);
    void paintGL();
};

MyOpenGL::MyOpenGL(QWidget *parent):QGLWidget(QGLFormat(QGL::SampleBuffers),parent)
{
    setAutoFillBackground(false);
}

MyOpenGL::~MyOpenGL()
{

}

void MyOpenGL::initializeGL()
{
    glShadeModel(GL_SMOOTH);
    glClearColor(0.0f,0.0f,0.0f,0.0f);
    glClearDepth(1.0f);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
}

void MyOpenGL::resizeGL(int w, int h)
{
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f,width()/height(),10.0f,100.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}

void MyOpenGL::paintGL()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    //glTranslatef(0.0,0.0,-10.0);

    glBegin(GL_TRIANGLES);
    glColor3f(1.0f,0.0f,0.0f);
    glVertex3f(-1.0f,0.0f,-10.0f);
    glColor3f(0.0f,1.0f,0.0f);
    glVertex3f(1.0f,0.0f,-10.0f);
    glColor3f(0.0f,0.0f,1.0f);
    glVertex3f(0.0f,4.0f,-10.0f);
    glEnd();

    glRotatef(90.0,0.0f,0.0f,-1.0f);

    glBegin(GL_TRIANGLES);
    glColor3f(1.0f,0.0f,0.0f);
    glVertex3f(-1.0f,0.0f,-10.0f);
    glColor3f(0.0f,1.0f,0.0f);
    glVertex3f(1.0f,0.0f,-10.0f);
    glColor3f(0.0f,0.0f,1.0f);
    glVertex3f(0.0f,4.0f,-10.0f);
    glEnd();

    glLoadIdentity();
}

int main(int argc,char * argv[])
{
    QApplication app(argc,argv);

    MyOpenGL * f = new MyOpenGL(NULL);
    f->show();

    return app.exec();
}

This is the pro file

SOURCES += \
    main.cpp

QT += opengl

This is the resulting app’s screen shot

enter image description here

As for as I know rotation won’t do any change in dimension. But here the dimension is changing .If anybody clear my doubt in this issue, I will be very thankful to him/her.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:51:25+00:00Added an answer on May 23, 2026 at 6:51 am

    I can’t say for certain what is going on, but I do see that there may be some problems.

    gluPerspective(45.0f,width()/height(),10.0f,100.0f);
    

    If width and height both return integers (and they probably do), then dividing one by the other will result in an integer. That’s not going to give you a proper aspect ratio. Cast one of them to a float to get a real aspect ratio.

    Next, try putting a glLoadIdentity() call at the top of the paintGL function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to learn how to add testing to existing code --
Trying to learn a bit of CSS and I want a horizontal navbar and
In trying to learn how to create objects in ActionScript, I have had no
I'm trying to learn C. As a C# developer, my IDE is Visual Studio.
I am trying to learn the keyboard shortcuts in Visual Studio in order to
I'm trying to learn RegEx in Ruby, based on what I'm reading in The
I'm trying to learn C++ so forgive me if this question demonstrates a lack
I am trying to learn some of the basic and advanced features of visual
I'm trying to learn to use SDL for a little game I'm writing ,
I am trying to learn CodeIgniter to use for a shopping site, but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.