I'm a novice in Qt5, want to make a simple programm with interactive 3D graphics. I create a new Qt Widgets app, following manuals I do QT += opengl in .pro, #include<QtOpenGL> in .h, and that's all. I even don't add any extra code, I click "build project" and get this:
/opt/qtsdk/5.5/gcc/include/QtGui/qopenglext.h:117: ошибка: typedef
'PFNGLDRAWRANGEELEMENTSPROC' is initialized (use decltype instead)
typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC) (GLenum mode,
GLuint start, GLuint end, GLsizei count, GLenum type, const void
*indices); 'GLenum' was not declared in this scope 'GLuint' was not declared in this scope 'GLsizei' was not declared in this scope
'GLenum' was not declared in this scope expected primary-expression
before 'const' typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC)
(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type,
const void *indices); typedef 'PFNGLTEXIMAGE3DPROC' is initialized
(use decltype instead) typedef void (APIENTRYP PFNGLTEXIMAGE3DPROC)
(GLenum target, GLint level, GLint internalformat, GLsizei width,
GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum
type, const void *pixels);
and same on and on till I stop building as I get the 8140th error, which isn't the last. :\
Please, help!! Tried everything, can't take it anymore
I installed Qt5 (lib and IDE together) by online-installation, then tried to fix them:
$ apt-get install libgl1-mesa-dev
$ sudo aptitude install mesa-common-dev
$ sudo apt-get install build-essential libfontconfig1
etc. Tried everything, that managed to find regarding my problem (though google says nothig useful solving exactly my problem)
OS: Linux Mint 17.1 Cinnamon 32bit
Video card: Intel Corporation 2nd Generation Core Processor Family Integrated Graphics Controller (Total crap. Maybe, that's an issue?)
OpenGL version: 3.0 Mesa 10.1.3 (Does QtOpengl use a default Оpengl, preinstalled on my laptop, or uses its own Opengl? Though, how do versions of Opengl and Qt correlate? Would Qt4-5 even work witn an old Opengl version?)
Qt version: 4.8.6 (At least console says so, but I'm not shure that projects aren't built with Qt5 libs. How can I explicitly specify the version I need to build the project by the way?)
Auto-detected Qt version: Desktop Qt 5.5.1 GCC 32bit
QMake version: 2.01a
Auto-detected compiler: GCC; debugger: GDB
Need your help very much! Thanks
The only code I have:
That's mainscene.h:
#ifndef MAINSCENE_H
#define MAINSCENE_H
#include <QMainWindow>
#include<QtOpenGL>
#include<QGLWidget>
class MainScene : public QMainWindow
{
protected:
void initializeGL();
void resizeGL(int w, int h);
void paintGL();
public:
Scene3D(QWidget* parent = 0);
};
#endif // MAINSCENE_H
That's the SimpleOpengl.pro:
QT += core gui
QT += opengl
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = SimpleOpengl
TEMPLATE = app
SOURCES += main.cpp
mainscene.cpp
HEADERS += mainscene.h
That's the main.cpp:
#include "mainscene.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainScene w;
w.show();
return a.exec();
}
(It's all wrong, isn't it?..)
Related
QT version: 5.12.0
OpenGL version: 4.5 core
Development environment: VS 2017
pro file:
QT += widgets
...
I have already add the glad.c file into my project, and ensure that the glad.h is included at the first place in every file.
But while I compile my project, all the other classes that using OpenGL functions are normal, except the class inherited from QOpenGLWidget.
MappingView.h
#include <glad/glad.h>
...
class MappingView : public QOpenGLWidget {
Q_OBJECT
public:
MappingView(QWidget * parent = nullptr);
~MappingView();
virtual void initializeGL();
virtual void resizeGL(int w, int h);
virtual void paintGL();
...
GLuint m_pointer_texture;
}
MappingView.cpp
MappingView::MappingView(QWidget * parent) : QOpenGLWidget(parent) {
}
MappingView::~MappingView() {
glDeleteTextures(1, &m_pointer_texture);
}
void MappingView::initializeGL() {
// load glad
if (!gladLoadGL()) {
return;
}
glGenTextures(1, &m_pointer_texture);
}
Compile error: C3861, cann't find glDeleteTextures.
When I click to the definition of glDeleteTextures in VS, it will jump to QOpenGLFunctions, but not glad.h. It seems that the OpenGL in QT and glad is conflicting. But my project doesn't use QOpenGLFunctions.
When I try to add a macro in MappingView.h,
#define QT_NO_OPENGL
all OpenGL functions in MappingView can be successfully found in glad.h, but the base class QOpenGLWidget cannot be found instead, which means that the MappingView class cannot be inherited from QOpenGLWidget any more.
I would be very appreciated if somebody could help me to resolve the problem, thanks!
I am trying to get a basic setup with GLFW and Vulkan for an upcoming project. I was trying to get a simple HelloTriangle Example to work. While the Vulkan library is building normally, the GLFW is throwing a ld: library not found for -lglfw3 on running the program. I am also unsure whether my HelloTriangle example is a working example; it was the most basic example I have to seen to test Vulkan.
Here is my CMakeList.txt:
cmake_minimum_required(VERSION 3.16)
project(OpenGLRun)
set(CMAKE_CXX_STANDARD 14)
set(glfw3_DIR /usr/local/Cellar/glfw/3.3.2/lib/cmake/glfw3)
add_executable(OpenGLRun main.cpp)
find_package(vulkan REQUIRED)
find_package(glm REQUIRED)
find_package(OpenGL REQUIRED)
find_package(glfw3 REQUIRED)
target_link_libraries(OpenGLRun Vulkan::Vulkan)
target_link_libraries(OpenGLRun glm)
target_link_libraries(OpenGLRun OpenGL::GL)
target_link_libraries(OpenGLRun glfw3)
And the main.cpp example code that I was trying to run for proof that everything was working:
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
#include <iostream>
#include <stdexcept>
#include <cstdlib>
const uint32_t WIDTH = 800;
const uint32_t HEIGHT = 600;
class HelloTriangleApplication {
public:
void run() {
initWindow();
initVulkan();
mainLoop();
cleanup();
}
private:
GLFWwindow* window;
void initWindow() {
glfwInit();
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
GLFWwindow *window = glfwCreateWindow(WIDTH, HEIGHT, "Vulkan", nullptr, nullptr);
}
private:
void initVulkan() {
}
void mainLoop() {
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
}
}
void cleanup() {
glfwDestroyWindow(window);
glfwTerminate();
}
};
int main() {
HelloTriangleApplication app;
try {
app.run();
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
And finally, for the future, would you recommend package managers in C++/CMake?
Thanks in advance
The GLFW Build Guide suggests that whether you are compiling and linking GLFW along with your application, or linking an installed GLFW to your application, you can link GLFW to your application using the glfw target (not glfw3). Change the target_link_libraries() command in your CMake to this:
target_link_libraries(OpenGLRun PRIVATE glfw)
Note, you should always provide the scoping argument when using the target-based commands such as this, to tell CMake whether this is a build requirement, a usage requirement, or both.
I have reinstalled Code::Blocks and GLFW3 after finally growing tired of not being able to experiment and do stuff in c++ on my pc for about one or two months, I got far enough to where I am trying to make a simple window that gets cleared. The problem is that the window doesn't get cleared at all except for pitch black darkness. At first I thought it might be because I use a function to draw the window, but that wasn't the issue either. I tried adding glBindFramebuffer(GL_FRAMEBUFFER,0); before the clear to see if that would fix the issue, but then the compiler said that glBindFramebuffer wasn't declared.
Here's main.cpp
#include <GLFW/glfw3.h>
void loop(GLFWwindow* window,bool &quit);
int main()
{
glfwInit();
glfwWindowHint(GLFW_VERSION_MAJOR,4);
glfwWindowHint(GLFW_VERSION_MINOR,5);
GLFWwindow* window=glfwCreateWindow(512,512,"Test",NULL,NULL);
glClearColor(1.0f,1.0f,1.0f,1.0f);
bool quit=false;
do
{
loop(window,quit);
}while(quit==false);
glfwTerminate();
return 0;
}
And loop.cpp
#include <GLFW/glfw3.h>
void loop(GLFWwindow* window,bool &quit){
glfwPollEvents();
if(glfwGetKey(window,GLFW_KEY_ESCAPE)==GLFW_PRESS)
quit=true;
glBindFramebuffer(GL_FRAMEBUFFER,0); <-Error here
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
}
EDIT: So after figuring out I need to load functions I've tried GLEW to no avail, GL3W doesn't seem to work in linux and all other options seems to be too god damned advanced for what it is and won't work in anyways.
I'm trying to compile a gtkmm application that uses cairomm for drawing.
It compiles fine using gtkmm3.0 but when I try to compile it using gtkmm2.4 i get:
error: ‘signal_draw’ was not declared in this scope
I'm using g++.
It seems that there is no signal_draw in gtkmm2.4(Am I wrong?). Is there any function/signal that can be used instead?
Thanks in advance.
Sorry for my bad English.
Some code:
class egclass: public Gtk::DrawingArea
{
public:
egclass();
virtual ~egclass();
virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr);
};
egclass::egclass()
{
#ifndef GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
signal_draw().connect(sigc::mem_fun(*this, &egclass::on_draw), false);
#endif
}
The older gtkmm 2.4 has on_expose_event instead:
virtual bool on_expose_event(GdkEventExpose* event);
If you need to create a cairo context for drawing, with the GTK+ C API it goes something like this:
cairo_t *cr;
cr = gdk_cairo_create (event->window);
gdk_cairo_region (cr, event->region);
cairo_clip (cr);
/* do your drawing */
cairo_destroy (cr);
... translating the snippet above to gtkmm is left as an exercise to the reader.
Also see the following links:
Porting from gtkmm-2.4 to gtkmm-3.0
Migrating from GTK+ 2.x to GTK+ 3
example_pixbufs.cc
I was trying to compile a Qt and OpenGL program under Code::Blocks in Ubuntu 10.04. I get the 'undefined reference to 'vtable for GLWidget'
#ifndef _GLWIDGET_H
#define _GLWIDGET_H
#include <QtOpenGL/QGLWidget>
#include "stdlib.h"
class GLWidget : public QGLWidget {
Q_OBJECT // must include this if you use Qt signals/slots
public:
GLWidget(QWidget *parent = 0);
~GLWidget();
protected:
void initializeGL();
void resizeGL(int w, int h);
void paintGL();
void keyPressEvent(QKeyEvent *event);
};
#endif /* _GLWIDGET_H */
I borrowed the code from this guy to see if it works, because mine wasn't working because of the same reason. Code
And here is the GLWidget.cpp:
#include <QtGui/QMouseEvent>
#include "glwidget.h"
GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent) {
setMouseTracking(true);
}
GLWidget::~GLWidget()
{
}
void GLWidget::initializeGL() {
...
}
void GLWidget::resizeGL(int w, int h) {
...
}
void GLWidget::paintGL() {
...
}
void GLWidget::keyPressEvent(QKeyEvent* event) {
...
}
}
I removed the code from the GL part to keep it shorter. Should you need it, I can always post it up.
#include <QtGui/QApplication>
#include <QtOpenGL/QGLWidget>
#include "glwidget.h"
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
GLWidget window;
window.resize(800,600);
window.show();
return app.exec();
}
In your project.pro file add
QT += opengl
So it knows that it has to link to GL libraries.
Clean your project and run qmake on it.
'undefined reference to 'vtable for GLWidget' most probably means that the definition of the first non inline virtual function of GLWidget isn't linked in the executable.
In the present case, my guess it is that it should be provided by the file generated by moc (but as I don't program for QT, I may be mistaken here).
This happens sometimes when adding Q_OBJECT to a header file and can mean a missing moc_ file.
I have found from personal experience doing the following has resolved the issue:
$ qmake filename.pro
$ make
I had this exact problem after adding Q_OBJECT to one of the header files in my project.
I was only getting this error message from within QT Creator, and not when I built my project from the Linux command line.
For me, the solution was to delete the YourProjectName-build-desktop folder which resides on the same level as your project directory. Then when I built the project from within QT Creator, it magically worked.