Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. Qt with OpenGL problems
Qt 6.11 is out! See what's new in the release blog

Qt with OpenGL problems

Scheduled Pinned Locked Moved Game Development
1 Posts 1 Posters 2.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    qmor
    wrote on last edited by
    #1

    Hello everyone. I'm trying to use Qq with OpenGL. I have some c++ classes what describes Scene, objects, textures, etc. I've create class MainWindow from QGLWidget, and overdrive it's methods.

    @
    #include "MainWindow.h"
    #include <iostream>
    #include <GL/gl.h>
    using namespace std;
    MainWindow::MainWindow(QWidget *parent) : QGLWidget(parent)
    {
    Scene=NULL;

    setFormat(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer));
    }
    void MainWindow::setScene(scene *sScene)

    {
    setFormat(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer));
    Scene=sScene;
    }

    void MainWindow::initializeGL()
    {
    ;
    GLfloat lightpos[]={1.0,1.0,-3.0,1.0};
    GLfloat lightcolor[]={1.0,1.0,1.0,1.0};
    GLfloat mat_specular[] ={1.0,1.0,1.0,1.0};
    cout << "GL init start" << endl;
    glClearColor(0.0,0.0,0.0,1.0);
    glShadeModel(GL_SMOOTH);

    glEnable(GL_BLEND);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_COLOR_MATERIAL);
    glDepthFunc(GL_LEQUAL);
    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
    glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
    glMaterialf(GL_FRONT,GL_SHININESS,128.0);
    glMaterialfv(GL_BACK,GL_SPECULAR,mat_specular);
    glMaterialf(GL_BACK,GL_SHININESS,128.0);

    glLightfv(GL_LIGHT0,GL_POSITION,lightpos);
    glLightfv(GL_LIGHT0,GL_DIFFUSE,lightcolor);

    glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_CULL_FACE);
    glEnable(GL_MULTISAMPLE);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);

    cout << "GL init end" << endl;

    }

    void MainWindow::resizeGL(int width, int height)
    {
    glViewport(0,0,(GLsizei) width, (GLsizei)height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustum(-1.0,1.0,-1.0,1.0,1.5,20000.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    }

    void MainWindow::paintGL()
    {
    if (Scene!=NULL)
    {
    cout << "Drawing" << endl;

    Scene->processObjects();
    Scene->Draw(); //this code is drawing all scene's objects

    }
    else
    {
    cout << "Scene is NULL" << endl;
    glClearDepth(1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);//Очистка цветового буфера и буфера глубины
    glLoadIdentity();
    }
    }

    @

    Now i'm trying to create scene and Application and have only the blank screen

    @
    int main(int argc, char **argv)
    {

    QApplication app(argc,argv);
    if(!QGLFormat::hasOpenGL())
    {
    cerr << "This system has no OpenGL support" << endl;
    return 1;
    }

    Vector3D<GLfloat> Rotation(0.1,0.1,0.0);

    scene Scene;

    MainWindow mainWindow;
    mainWindow.setScene(&Scene);

    Model3D Ico((char *)"ccc1.obj");//while loading object textures loading too
    Ico.setRotationSpeed(Rotation);
    Rotation.set(0.0,-10.0,0.0);
    Scene.addObject(&Ico);
    Light light(0.0,0.0,4.0,1.0,0.7,0.9);
    Scene.setLight(light);
    Scene.enableAA(true);

    mainWindow.resize(800,800);
    mainWindow.show();

    return app.exec();
    }
    @
    What i'm doind wrong?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved