[Qt] QOpenGLWidget override initializeGL and paintGL
max
max at olo.com.pl
Fri May 26 21:43:38 CEST 2017
> Really don't know :) Never played with OpenGL. Try to instantiate
> QApplication, create QWindow and via it's QSurfaceType set to OpenGL
> .. and see what happens :)
>
> zeljko
>
For OpenGL we need "QOpenGLContext" only ;)
All function glXX are from "GL/gl.h"
Sample application in QT
////////////////////////////////////////////////////////////
//////////////// main.cpp
#include<QApplication>
#include<QWindow >
#include<QOpenGLContext >
//#include <QOpenGLFunctions>
#include<GL/gl.h >//
intmain(intargc,char*argv[])
{
QApplicationa(argc,argv);
QWindow*embed;
embed=newQWindow;
embed->setSurfaceType(QWindow::OpenGLSurface);
embed->setGeometry(QRect(50,50,640,480));
embed->setVisible(true);
QOpenGLContext*m_context;
m_context=newQOpenGLContext();
m_context->create();
m_context->makeCurrent(embed);
// <QOpenGLFunctions> version
//QOpenGLFunctions *f = m_context->functions();
//f->glClearColor(1.0,0,0,1.0);
//f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// <GL/gl.h> VERSION
glClearColor(1.0,0,0,1.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
// Define shapes enclosed within a pair of glBegin and glEnd
glBegin(GL_QUADS);// Each set of 4 vertices form a quad
glColor3f(1.0f,0.0f,0.0f);// Red
glVertex2f(-0.8f,0.1f);// Define vertices in counter-clockwise (CCW) order
glVertex2f(-0.2f,0.1f);// so that the normal (front-face) is facing you
glVertex2f(-0.2f,0.7f);
glVertex2f(-0.8f,0.7f);
glColor3f(0.0f,1.0f,0.0f);// Green
glVertex2f(-0.7f,-0.6f);
glVertex2f(-0.1f,-0.6f);
glVertex2f(-0.1f,0.0f);
glVertex2f(-0.7f,0.0f);
glColor3f(0.2f,0.2f,0.2f);// Dark Gray
glVertex2f(-0.9f,-0.7f);
glColor3f(1.0f,1.0f,1.0f);// White
glVertex2f(-0.5f,-0.7f);
glColor3f(0.2f,0.2f,0.2f);// Dark Gray
glVertex2f(-0.5f,-0.3f);
glColor3f(1.0f,1.0f,1.0f);// White
glVertex2f(-0.9f,-0.3f);
glEnd();
m_context->swapBuffers(embed);
returna.exec();
}
////////////////////////////////////////////////////////////
#-------------------------------------------------
#
#ProjectcreatedbyQtCreator2017-05-26T18:32:13
#
#-------------------------------------------------
QT+=coregui
LIBS+=-lglut-lopengl32
greaterThan(QT_MAJOR_VERSION,4):QT+=widgets
TARGET=nienazwany1
TEMPLATE=app
SOURCES+=main.cpp
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/qt/attachments/20170526/e47b0f9f/attachment-0002.html>
More information about the Qt
mailing list