Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
TriangleInOneFile_Qt5OpenGLES20Cpp (with a link to a WebGL 1.0 TypeScr...
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
// Minimal OpenGL example that works on Notebook and Android // Add to .pro file: win32: LIBS += -lopengl32 // Version in WebGL 1.0, TypeScript: https://plnkr.co/edit/gAfPR7ZIKjJXulDI?open=main.ts&preview #ifdef _WIN32 #include <windows.h> extern "C" __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; extern "C" __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 0x00000001; #endif #include <QApplication> #include <QOpenGLWidget> #include <QOpenGLShaderProgram> #include <QOpenGLBuffer> class Widget : public QOpenGLWidget { Q_OBJECT public: Widget(QWidget *parent = nullptr) : QOpenGLWidget(parent) { } private: QOpenGLShaderProgram m_program; QOpenGLBuffer m_vertPosBuffer; void initializeGL() override { glClearColor(0.5f, 0.8f, 0.7f, 1.f); resize(400, 500); const char *vertShaderSrc = "attribute vec3 aPosition;" "void main()" "{" " gl_Position = vec4(aPosition, 1.0);" "}"; const char *fragShaderSrc = "void main()" "{" " gl_FragColor = vec4(0.5, 0.2, 0.9, 1.0);" "}"; m_program.addShaderFromSourceCode(QOpenGLShader::Vertex, vertShaderSrc); m_program.addShaderFromSourceCode(QOpenGLShader::Fragment, fragShaderSrc); m_program.link(); m_program.bind(); float vertPositions[] = { -0.5f, -0.5f, 0.f, 0.5f, -0.5f, 0.f, 0.f, 0.5f, 0.f }; m_vertPosBuffer.create(); m_vertPosBuffer.bind(); m_vertPosBuffer.allocate(vertPositions, sizeof(vertPositions)); m_program.bindAttributeLocation("aPosition", 0); m_program.setAttributeBuffer(0, GL_FLOAT, 0, 3); m_program.enableAttributeArray(0); } void paintGL() override { glClear(GL_COLOR_BUFFER_BIT); glDrawArrays(GL_TRIANGLES, 0, 3); } void resizeGL(int w, int h) override { glViewport(0, 0, w, h); } }; #include "main.moc" int main(int argc, char *argv[]) { QApplication a(argc, argv); Widget w; w.show(); return a.exec(); }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
edit mode
|
history