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. Need help; QPushButton to control OpenGL
Forum Updated to NodeBB v4.3 + New Features

Need help; QPushButton to control OpenGL

Scheduled Pinned Locked Moved Game Development
9 Posts 3 Posters 4.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.
  • D Offline
    D Offline
    doughng
    wrote on last edited by
    #1

    Hi,
    I'm absolutely new to programming, but I've been reading about OpenGL/Qt, and I learnt to render an OpenGL object using QGLWidget. Now I'm trying to create a GUI in which OpenGL objects are only rendered whenever QPushButton is clicked. I read about slot/signal, but I still dont understand where to place my functions, and how to implement it. Please I need help!

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      Did you try to do some of the basic tutorials on Qt programming?

      1 Reply Last reply
      0
      • D Offline
        D Offline
        doughng
        wrote on last edited by
        #3

        The ones I found were direct examples of slots/signals...nothing to do with OpenGL. I would appreciate any good ones that relate or has the same idea as what I want to achieve

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          You just implement your OpenGL code in the slot's body. Then connect QPushButton's clicked() signal to your new slot. I think it was you who sent me a PM about it? I've linked some handy docs there.

          (Z(:^

          1 Reply Last reply
          0
          • D Offline
            D Offline
            doughng
            wrote on last edited by
            #5

            yeah, its me :)

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              I find the best way to learn programming is to try - you'll learn as soon as you get it to work yourself. This way, it's your thinking that analyses the problem, finds a solution, and then finds a way to implement that solution in a given programming language.

              (Z(:^

              1 Reply Last reply
              0
              • D Offline
                D Offline
                doughng
                wrote on last edited by
                #7

                I'm on it, thanks very much

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  doughng
                  wrote on last edited by
                  #8

                  I worked on a basic GLUT model in Qt, and it shows a white screen and crashes, I need help.

                  The program has unexpectedly finished.
                  C:\QtGL\myGL-build-desktop-Qt_4_7_4_for_Desktop
                  -MinGW_4_4__Qt_SDK__Debug\debug\myGL.exe exited with code -1073741819

                  Here're my codes:

                  GLWidget.cpp
                  @#include "glwidget.h"
                  #include<GL/glut.h>

                  GLWidget::GLWidget(QWidget *parent) :
                  QGLWidget(parent)
                  {
                  }
                  void GLWidget::initializeGL()
                  {
                  glClearColor(0.0, 0.0, 0.0, 0); // Background Color

                  }

                  void GLWidget::resizeGL(int width, int height)
                  {
                  glViewport(0, 0, width, height);
                  glMatrixMode(GL_PROJECTION);
                  glLoadIdentity();
                  gluPerspective(45.0, (float)width / (float)height, 0.1, 1000.0);
                  glMatrixMode(GL_MODELVIEW);
                  glLoadIdentity();
                  gluLookAt(
                  0.0, 0.0, 200.0, // eye location
                  0.0, 0.0, 0.0, // center location
                  0.0, 1.0, 0.0); // up vector
                  }

                  void GLWidget::drawGL(){
                  glColor3f(1.0f, 0.0f, 0.0f); //set cube color
                  glutWireTeapot(30); //use the premade glut function to draw a wire cube of size 30
                  glutSwapBuffers();
                  }

                  void GLWidget::paintGL()
                  {
                  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
                  glEnable(GL_DEPTH_TEST);
                  drawGL();

                  }
                  @

                  GLWidget.h
                  @#ifndef GLWIDGET_H
                  #define GLWIDGET_H

                  #include <QGLWidget>

                  class GLWidget : public QGLWidget
                  {
                  Q_OBJECT

                  public:
                  explicit GLWidget(QWidget *parent = 0);

                  protected:
                  void initializeGL();
                  void resizeGL(int width, int height);
                  void paintGL();

                  private:
                  void drawGL();

                  signals:

                  public slots:

                  };

                  #endif // GLWIDGET_H
                  @

                  Mainwidget.h
                  @#ifndef MAINWIDGET_H
                  #define MAINWIDGET_H

                  #include <QWidget>

                  namespace Ui {
                  class MainWidget;
                  }

                  class MainWidget : public QWidget
                  {
                  Q_OBJECT

                  public:
                  explicit MainWidget(QWidget *parent = 0);
                  ~MainWidget();

                  private:
                  Ui::MainWidget *ui;
                  };

                  #endif // MAINWIDGET_H
                  @

                  Main.cpp
                  @#include <QtGui/QApplication>
                  #include <GL/glut.h>
                  #include "mainwidget.h"

                  int main(int argc, char *argv[])
                  {
                  QApplication a(argc, argv);
                  MainWidget w;
                  w.show();

                  return a.exec&#40;&#41;;
                  

                  }
                  @

                  Mainwidget.cpp
                  @#include "mainwidget.h"
                  #include "ui_mainwidget.h"

                  MainWidget::MainWidget(QWidget *parent) :
                  QWidget(parent),
                  ui(new Ui::MainWidget)
                  {
                  ui->setupUi(this);
                  }

                  MainWidget::~MainWidget()
                  {
                  delete ui;
                  }
                  @

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    doughng
                    wrote on last edited by
                    #9

                    I found the problem, I'm using a single buffer, not double buffer. I commented glutSwapBuffers() out and it works fine.

                    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