Skip to content

imgui_win32_opengl3 example #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
.cache
.DS_Store
.ideas
build
build

*.pdb
*.ilk
*.exp
*.vst3
*.lib
*.rdi
73 changes: 73 additions & 0 deletions example/imgui_win32_opengl3/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import os

# execute this script from a "x64 Native Tools Command Prompt for VS 2022"
# or by adding "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build" to
# your path and execute the "vcvars64.bat" script from any shell to setup the MSVC compiler.

vst3 = True

workspace_dir = os.getcwd()
CPLUG_dir = workspace_dir + "/../.."

# flags
flags = "/nologo /LD /MD /utf-8 /Zi /EHsc /MP3 /W3"
output_name = ""
output_extension = ""

if vst3:
flags += " /LD"
output_name += "plugin"
output_extension += "vst3"
else:
output_name += "plugin"
output_extension += "exe"

includes = " ".join([
f"/I{CPLUG_dir}/src",
"/Iimgui",
"/Iimgui/backends",
f"/FI{workspace_dir}/config.h"
])

sources = " ".join([
"main.cpp",

"imgui/imgui.cpp",
"imgui/backends/imgui_impl_win32.cpp",
"imgui/backends/imgui_impl_opengl3.cpp",

"imgui/imgui_draw.cpp",
"imgui/imgui_tables.cpp",
"imgui/imgui_widgets.cpp",
])

if vst3:
sources += f" {CPLUG_dir}/src/cplug_vst3.c"
else:
sources += f" {CPLUG_dir}/src/cplug_standalone_win.c"

libs = " ".join([
"opengl32.lib",
"kernel32.lib",
"user32.lib",
"gdi32.lib",
])

if not vst3 :
libs += " Ole32.lib"


command = f"cl {flags} {sources} /Fe:{output_name}.{output_extension} /Fd:{output_name}.pdb {includes} /link {libs}"
print(command)
return_code = os.system(command)


if return_code != 0:
print("Problems during compilation exiting")
exit(1)

print("Cleaning")
for file in filter(lambda string : ".obj" in string, os.listdir()):
os.remove(file)

print("Done")
43 changes: 43 additions & 0 deletions example/imgui_win32_opengl3/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef PLUGIN_CONFIG_H
#define PLUGIN_CONFIG_H

#define CPLUG_COMPANY_NAME "CPLUG"
#define CPLUG_COMPANY_EMAIL ""
#define CPLUG_PLUGIN_NAME "CPLUG ImGui"
#define CPLUG_PLUGIN_URI "http://github.com/Tremus/CPLUG"
#define CPLUG_PLUGIN_VERSION "1.0.0"

#define CPLUG_IS_INSTRUMENT 1

#define CPLUG_NUM_INPUT_BUSSES 1
#define CPLUG_NUM_OUTPUT_BUSSES 1
#define CPLUG_WANT_MIDI_INPUT 1
#define CPLUG_WANT_MIDI_OUTPUT 1

#define CPLUG_WANT_GUI 1
#define CPLUG_GUI_RESIZABLE 1

// See list of categories here: https://steinbergmedia.github.io/vst3_doc/vstinterfaces/group__plugType.html
#define CPLUG_VST3_CATEGORIES "Fx|Stereo"

#define CPLUG_VST3_TUID_COMPONENT 'cplg', 'comp', 'xmpl', 0
#define CPLUG_VST3_TUID_CONTROLLER 'cplg', 'edit', 'xmpl', 0

#define CPLUG_AUV2_VIEW_CLASS CPLUGExampleView
#define CPLUG_AUV2_VIEW_CLASS_STR "CPLUGExampleView"
static const unsigned kAudioUnitProperty_UserPlugin = 'plug';

#define CPLUG_CLAP_ID "com.cplug.example"
#define CPLUG_CLAP_DESCRIPTION "Example plugin"
#define CPLUG_CLAP_FEATURES CLAP_PLUGIN_FEATURE_INSTRUMENT, CLAP_PLUGIN_FEATURE_STEREO

// Examples of using common parameter types
enum Parameters
{
kGain,
kParameterCount
};

#define CPLUG_NUM_PARAMS 1

#endif // PLUGIN_CONFIG_H
21 changes: 21 additions & 0 deletions example/imgui_win32_opengl3/imgui/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014-2024 Omar Cornut

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
961 changes: 961 additions & 0 deletions example/imgui_win32_opengl3/imgui/backends/imgui_impl_opengl3.cpp

Large diffs are not rendered by default.

66 changes: 66 additions & 0 deletions example/imgui_win32_opengl3/imgui/backends/imgui_impl_opengl3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// dear imgui: Renderer Backend for modern OpenGL with shaders / programmatic pipeline
// - Desktop GL: 2.x 3.x 4.x
// - Embedded GL: ES 2.0 (WebGL 1.0), ES 3.0 (WebGL 2.0)
// This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..)

// Implemented features:
// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID!
// [x] Renderer: Large meshes support (64k+ vertices) with 16-bit indices (Desktop OpenGL only).

// About WebGL/ES:
// - You need to '#define IMGUI_IMPL_OPENGL_ES2' or '#define IMGUI_IMPL_OPENGL_ES3' to use WebGL or OpenGL ES.
// - This is done automatically on iOS, Android and Emscripten targets.
// - For other targets, the define needs to be visible from the imgui_impl_opengl3.cpp compilation unit. If unsure, define globally or in imconfig.h.

// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
// Learn about Dear ImGui:
// - FAQ https://dearimgui.com/faq
// - Getting Started https://dearimgui.com/getting-started
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
// - Introduction, links and more at the top of imgui.cpp

// About GLSL version:
// The 'glsl_version' initialization parameter should be nullptr (default) or a "#version XXX" string.
// On computer platform the GLSL version default to "#version 130". On OpenGL ES 3 platform it defaults to "#version 300 es"
// Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp.

#pragma once
#include "imgui.h" // IMGUI_IMPL_API
#ifndef IMGUI_DISABLE

// Follow "Getting Started" link and check examples/ folder to learn about using backends!
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = nullptr);
IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown();
IMGUI_IMPL_API void ImGui_ImplOpenGL3_NewFrame();
IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data);

// (Optional) Called by Init/NewFrame/Shutdown
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateFontsTexture();
IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyFontsTexture();
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateDeviceObjects();
IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects();

// Configuration flags to add in your imconfig file:
//#define IMGUI_IMPL_OPENGL_ES2 // Enable ES 2 (Auto-detected on Emscripten)
//#define IMGUI_IMPL_OPENGL_ES3 // Enable ES 3 (Auto-detected on iOS/Android)

// You can explicitly select GLES2 or GLES3 API by using one of the '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line.
#if !defined(IMGUI_IMPL_OPENGL_ES2) \
&& !defined(IMGUI_IMPL_OPENGL_ES3)

// Try to detect GLES on matching platforms
#if defined(__APPLE__)
#include <TargetConditionals.h>
#endif
#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__))
#define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es"
#elif defined(__EMSCRIPTEN__) || defined(__amigaos4__)
#define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100"
#else
// Otherwise imgui_impl_opengl3_loader.h will be used.
#endif

#endif

#endif // #ifndef IMGUI_DISABLE
Loading