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 8938471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:37:59+00:00 2026-06-15T10:37:59+00:00

I am learning with opengl-tutorial.org, I’m using QT Too, When I move the mouse,

  • 0

I am learning with opengl-tutorial.org, I’m using QT Too, When I move the mouse, the MVP matrix is updated, it works well. But the screen is not showing up the changes until I press the Alt Key. I don’t know why, is it an issue of QT or OpenGL?

InitGL Function:

programId = this->createPorgram(":/glsl/VertexShader.glsl",":/glsl/FragmentShader.glsl");
if(programId==-1){
    emit blewUpApplication();
    return;
}

glClearColor(0.0,0.0,0.0,1.0);
glEnable(GL_CULL_FACE);
glEnable(GL_MULTISAMPLE); // Enables multisampling for a better look
//glEnable(GL_BLEND); // Enable textures with alpha channel and alpha channels colors
glEnable(GL_TEXTURE_2D);
glEnable(GL_ALPHA_TEST);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
// Bla bla bla, the rest does not matters.

PaintGL Function:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clears the screen and paint the bg with the color specified on glClearColor

float currT = float(tmr.elapsed() / 1000.0f);
if((currT-lastTime)>=1.0f){
    lastTime+=1.0f;
}
deltaTime = (float)(currT-lastTime);

glm::mat4 Project = this->getMatrixProjection();
glm::mat4 View = this->getMatrixView();
glm::mat4 Model = glm::mat4(1.0f);
glm::mat4 MVP = Project * View * Model;

glUseProgram(programId);

GLuint MatrixId = glGetUniformLocation(programId,"MVP");
glUniformMatrix4fv(MatrixId,1,GL_FALSE,glm::value_ptr(MVP));

glActiveTexture(cursor_texture);
glBindTexture(GL_TEXTURE_2D,cursor_texture);

glUniform1i(glGetUniformLocation(programId,"textura"),cursor_texture);
// Draw or triangles

glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);   

glBindBuffer(GL_ARRAY_BUFFER,trianglebuffer[0]);
glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,0,(void*)0);


glBindBuffer(GL_ARRAY_BUFFER,trianglebuffer[1]);
glVertexAttribPointer(1,2,GL_FLOAT,GL_FALSE,0,(void*)0);


glDrawArrays(GL_TRIANGLES,0,12*3);

glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);

glUseProgram(0);

Mouse Move Function:

mousepos[0] = evt->x();
    mousepos[1] = evt->y();
    horzAn += mouseSpeed * deltaTime * float(this->width()/2 - mousepos[0]);
    vertAn += mouseSpeed * deltaTime * float(this->height()/2 - mousepos[1]);

    CmDirect = glm::vec3(cos(horzAn) * sin(vertAn), sin(vertAn), cos(horzAn) * cos(vertAn));
    glm::vec3 RgtVc = glm::vec3(sin(horzAn - 3.14f/2.0f),0,cos(horzAn - 3.14f/2.0f));
    UpVc = glm::cross(RgtVc,CmDirect);

    Proj = glm::perspective(Zoom,4.0f/3.0f,0.1f,100.0f);
    Vw = glm::lookAt(PosCm,PosCm+CmDirect,UpVc);
    this->cursor().setPos(suppose_x,suppose_y);

Shaders:

// Fragment
#version 330 core
out vec3 color;
in vec2 thcoord;
in vec2 UV;
uniform sampler2D d_textura;
void main(){
color = texture(d_textura,thcoord).rgb;
}
// Vertex
#version 330 core
layout(location = 0) in vec3 vertexPosition_modelspace;
layout(location = 1) in vec2 tcoord;
out vec2 thcoord;
uniform mat4 MVP;
void main(){
vec4 v = vec4(vertexPosition_modelspace,1);
thcoord=tcoord;
gl_Position = MVP * v;
}

I know that the matrix operation is working good because the effects change when I press the alt key (only one time happens).

  • 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-15T10:38:00+00:00Added an answer on June 15, 2026 at 10:38 am

    You should add update request to the end of your mouseMoveEvent handler for Qt to know that widget needs repaint. update() or repaint() should do the trick.

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

Sidebar

Related Questions

I'm learning OpenGL 3.3, using some tutorials (http://opengl-tutorial.org). In the tutorial I'm using, there
Well, I have been learning openGL with this tutorial: opengl-tutorial.org. That tutorial do not
I need to visualize 3D point clouds using C++, I started learning OpenGL but
I want to start learning OpenGL but I don't really want to have to
I'm learning OpenGL ES. When I'm using texture for triangle, I meet error. Here
I'm learning a spot of 3d opengl, and it's going rather well, I've got
I'm learning OpenGL from this tutorial: http://openglbook.com/the-book/ . I have problem with shaders. I'm
I have a question - I am learning OpenGL ES 2.0 from this tutorial
I recently satrted learning OpenGL, and it seems pretty intuitive so far, but this
I've found this tutorial: http://www.arcsynthesis.org/gltut/index.html The tutorial depends on the Unofficial OpenGL SDK (http://glsdk.sourceforge.net/docs/html/pg_build.html).

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.