Qt with OpenGL problems



  • 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?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.