Jump to content

View more

Image of the Day

Working on an auto spawn system. #gamedev #indiedev #screenshotsaturday https://t.co/Mm2kfekz7b
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

Opengl qt

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 shawk08033   Members   


Posted 26 April 2014 - 03:09 PM

I am trying to display a 64x64 in opengl. The texture loads but I cant get it to display in a square and on the top left corner of the screen. Heres my code for the GLWidget in qt 

#include "glwidget.h"

GLWidget::GLWidget(QWidget *parent) :

void GLWidget::initializeGL(){
    glClearColor(1, 1, 1 , 0);
    gluPerspective(45, 640/480, 1, 500);
    GLWidget::loadTexture2(":/images/Block.bmp", GLWidget::backgroundimage);

void GLWidget::paintGL(){
        glClearColor(0.4f, 0.1f, 0.1f, 1.0f);
        glBindTexture(GL_TEXTURE_2D, backgroundimage);

            glTexCoord2f(0,1); glVertex2f(0, 0);
            glTexCoord2f(0,0); glVertex2f(0, 64);
            glTexCoord2f(1,0); glVertex2f(64, 0);
            glTexCoord2f(1,1); glVertex2f(64, 64);


void GLWidget::resizeGL(int w, int h){


QImage GLWidget::loadTexture2(char *filename, GLuint &textureID){
    glEnable(GL_TEXTURE_2D); // Enable texturing

    glGenTextures(1, &textureID); // Obtain an id for the texture
    glBindTexture(GL_TEXTURE_2D, textureID); // Set as the current texture

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    QImage im(filename);
    QImage tex = QGLWidget::convertToGLFormat(im);

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width(), tex.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, tex.bits());



    return tex;

#2 BitMaster   Members   


Posted 28 April 2014 - 01:21 AM

You are setting a perspective matrix in whatever matrix state happens to be activated when you call it. You do not set any of the others (I'm unsure if QGLWidget guarantees if they will be set to the identity). Even if that does not cause a problem the near clipping plane is at z=1 while you render at z=0 (note you cannot set the near clipping plane to 0).

Ignoring that, gluPerspective is the completely wrong choice when you want to render in screen coordinates.

However, none of that is really important because you are learning old, deprecated OpenGL. Unless you are needing that knowledge for a very specific legacy project I would strongly advice to learn modern OpenGL instead of something you mostly have to unlearn later on.

Also note that depending on the Qt version you downloaded, you might not even have real OpenGL and instead will be using DirectX through ANGLE. It's not possible to see all the headers involved, but if you included something like GLEW or the system OpenGL you might be trying to a non-existing OpenGL context while ignoring the Qt-provided emulated context.

Edited by BitMaster, 28 April 2014 - 01:21 AM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.