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

  • SEARCH
  • Home
  • 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 9199549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:33:28+00:00 2026-06-17T22:33:28+00:00

I got a problem with drawing on a QGLWidget. I have several quads on

  • 0

I got a problem with drawing on a QGLWidget. I have several quads on the widget which I can move around when pressing some keys. As long as I just draw quads, everything works fine but now I want to add some lines using:

    glBegin(GL_LINE);
glColor3f(c[0], c[1], c[2]);
glVertex3f(v1.x, v1.y, v1.z);
glVertex3f(v2.x, v2.y, v2.z);
glEnd;

The drawing also works fine, but the clearing of the glwidget doesn’t work anymore. Means that I see everything I ever drawed on it. Just to mention.
I tried the same with GLUT using the same initializations and it worked, but since I have switched to Qt it doesn’t work anymore.
paintGL(), resizeGL() and initializeGL() are below.

void GLWidget::paintGL() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0f, 0.0f, 0.0f, 0.0f, -10.0f, -20.0f, 0.0f, 20.0f, -10.0f);

glTranslatef(0.0f, -30.0f, -40.0f);
glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
glRotatef(s_deg, 0.0f, 0.0f, 1.0f);
glRotatef(s_deg2, cos(DEGRAD(s_deg)), sin(DEGRAD(s_deg)), 0.0f);


float colors[8][3] = {
    0.5, 0.0, 0.0,
    0.0, 0.5, 0.0,
    0.0, 0.0, 0.5,
    1.0, 0.5, 0.5,
    0.5, 1.0, 0.5,
    0.5, 0.5, 1.0,
    0.9, 0.9, 0.9,
    0.1, 0.1, 0.1,

}; //red, green, blue, red shiny, green shiny, blue shine, light grey, dark grey

for(int i=0;i<glBoxes.size();i++) {
    glBoxes.at(i).setColor(colors[i]);
    glBoxes.at(i).drawCuboid();
    glBoxes.at(i).drawCuboidGrid();
}

}

void GLWidget::initializeGL() {    
glDepthFunc(GL_LESS);
glClearColor(0.2, 0.2, 0.2, 0.2);
glClearDepth(1.0);

}

void GLWidget::resizeGL(int width, int height) {    
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0.0f, 0.0f, (float)width, (float)height);
glLoadIdentity();
gluPerspective(45.0f, (float)width/(float)height, 0.5f, 100.0f);
glMatrixMode(GL_MODELVIEW);

}

any Ideas?

  • 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-06-17T22:33:30+00:00Added an answer on June 17, 2026 at 10:33 pm

    The tokens accepted by glBegin are

    • GL_POINTS
    • GL_LINES
    • GL_TRIANGLES
    • GL_TRIANGLE_FAN
    • GL_TRIANGLE_STRIP
    • GL_QUADS
    • GL_QUAD_STRIP

    and

    • GL_POLYGON

    The token used by you, GL_LINE (not the missing trailing S) is not valid for glBegin.


    The statement glEnd; will evaluate the address of the function glEnd and silently discard the result. Could it be, that you have a Pascal or Delphi background? In C like languages you have to add a matched pair of parentheses to make it a function call. Functions that don’t take a parameter are called with an empty pair of parentheses. E.g. in your case glEnd();.


    Not related to your problem. All of the code in resizeGL should go to the head of paintGL (use the widget’s width() and height() getters). Also what you have in initializeGL belongs to paintGL.

    The proper use of initializeGL is to do one-time initialization, like loading textures, and shaders, preparing FBOs and such.

    resizeGL is meant to re-/initialize stuff that depends on the window’s size and which is quite time consuming to change, like renderbuffers and/or textures used as attachment in FBOs used for window sized post-processing or similar. Setting the projection matrix does not belong there, and neither does the viewport. Those go into paintGL.

    glDepthFunc, glClearColor and glClearDepth directly influence the drawing process and as such belong with the drawing code.

    Also you should not use the immediate mode (glBegin … glEnd) at all. It’s been outdated ever since OpenGL-1.1 was released over 15 years ago. Use Vertex Arrays, with the possible addition of Buffer Objects.

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

Sidebar

Related Questions

got a problem, can't get my head around this jquery and would appreciate your
I have got some problem implementing bullet physics into my opengl game. The thing
Im drawing some polygons with PHP GD imagepolygon(). The problem is that i got
I got problem with sending data in Android using httpPost. I found some example,
I've got problem with DirectX in C#. I want to draw some lines. Firstly
have a nice day. I got problem when trying to create an image from
Previously, I have worked on local notifications, but I got problem in it now.
I got stuck just with one problem: I don't have even an idea why
I've got a little text drawing puzzle under Win32. I'm trying to draw some
I've got a bit of a problem with some jquery. The code works fine,

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.