22 #ifdef IGRAPHICS_NANOVG 55 nvgDeleteFramebuffer(mFBO);
67 nvgDeleteFramebuffer(mFBO);
69 mFBO = nvgCreateFramebuffer(vg, w, h, 0);
71 invalidateFBO =
false;
79 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &mInitialFBO);
81 nvgBindFramebuffer(mFBO);
82 nvgBeginFrame(vg, static_cast<float>(w), static_cast<float>(h), static_cast<float>(g.
GetScreenScale()));
84 glGetIntegerv(GL_VIEWPORT, vp);
86 glViewport(0, 0, w, h);
88 glScissor(0, 0, w, h);
89 glClearColor(0.f, 0.f, 0.f, 0.f);
90 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
93 glViewport(vp[0], vp[1], vp[2], vp[3]);
96 glBindFramebuffer(GL_FRAMEBUFFER, mInitialFBO);
99 APIBitmap apibmp {mFBO->image, w, h, 1, 1.};
100 IBitmap bmp {&apibmp, 1,
false};
104 g.
DrawText(mText,
"UNSUPPORTED", mRECT);
110 invalidateFBO =
true;
115 invalidateFBO =
true;
123 auto compileShader = [](GLenum shaderType,
const char *src) {
124 GLuint shader = glCreateShader(shaderType);
125 glShaderSource(shader, 1, &src, NULL);
126 glCompileShader(shader);
128 GLint isCompiled = 0;
129 glGetShaderiv(shader, GL_COMPILE_STATUS, &isCompiled);
133 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength);
134 char *buf = (
char*)malloc(maxLength+1);
135 glGetShaderInfoLog(shader, maxLength, &maxLength, buf);
144 auto createProgram = [](GLuint vertexShader, GLuint fragmentShader) {
145 GLuint program = glCreateProgram();
146 glAttachShader(program, vertexShader);
147 glAttachShader(program, fragmentShader);
148 glBindAttribLocation(program, 0,
"apos");
149 glBindAttribLocation(program, 1,
"acolor");
150 glLinkProgram(program);
154 static const char vs_str[] =
155 "attribute vec4 apos;" 156 "attribute vec4 acolor;" 157 "varying vec4 color;" 160 "gl_Position = apos;" 162 GLuint vs = compileShader(GL_VERTEX_SHADER, vs_str);
164 static const char fs_str[] =
166 "precision lowp float;" 168 "varying vec4 color;" 169 "uniform vec4 color2;" 171 "gl_FragColor = color*color2;" 173 GLuint fs = compileShader(GL_FRAGMENT_SHADER, fs_str);
175 GLuint program = createProgram(vs, fs);
176 glUseProgram(program);
178 static const float posAndColor[] = {
180 -0.6f, -0.6f, 1, 0, 0,
181 0.6f, -0.6f, 0, 1, 0,
186 glGenBuffers(1, &vbo);
187 glBindBuffer(GL_ARRAY_BUFFER, vbo);
188 glBufferData(GL_ARRAY_BUFFER,
sizeof(posAndColor), posAndColor, GL_STATIC_DRAW);
189 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 20, 0);
190 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 20, (
void*)8);
191 glEnableVertexAttribArray(0);
192 glEnableVertexAttribArray(1);
194 float color2[4] = { 0.0f, 1.f, 0.0f, 1.0f };
195 glUniform4fv(glGetUniformLocation(program,
"color2"), 1, color2);
196 glDrawArrays(GL_TRIANGLES, 0, 3);
201 NVGframebuffer* mFBO =
nullptr;
203 bool invalidateFBO =
true;
219 g.
DrawText(mText,
"UNSUPPORTED", mRECT);
The lowest level base class of an IGraphics control.
Used to manage a rectangular area, independent of draw class/platform.
virtual void OnResize()
Called when IControl is constructed or resized using SetRect().
User-facing bitmap abstraction that you use to manage bitmap data, independant of draw class/platform...
virtual void DrawDottedRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0, float thickness=1.f, float dashLen=2.f)
Draw a dotted rectangle to the graphics context.
bool mMouseIsOver
if mGraphics::mHandleMouseOver = true, this will be true when the mouse is over control.
Used for choosing a drawing backend.
float GetScreenScale() const
Gets the screen/display scaling factor, e.g.
int WindowHeight() const
Gets the height of the graphics context including draw scaling.
void SetTooltip(const char *str)
Set a tooltip for the control.
void DrawText(const IText &text, const char *str, const IRECT &bounds, const IBlend *pBlend=0)
Draw some text to the graphics context in a specific rectangle.
This file contains the base IControl implementation, along with some base classes for specific types ...
float GetDrawScale() const
Gets the graphics context scaling factor.
IControl(const IRECT &bounds, int paramIdx=kNoParameter, IActionFunction actionFunc=nullptr)
Constructor.
Control to test Drawing in using OpenGL in supporting backends.
The lowest level base class of an IGraphics context.
virtual void FillRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0)
Fill a rectangular region of the graphics context with a color.
virtual void DrawFittedBitmap(const IBitmap &bitmap, const IRECT &bounds, const IBlend *pBlend=0)
Draw a bitmap (raster) image to the graphics context, scaling the image to fit the bounds...
A base class interface for a bitmap abstraction around the different drawing back end bitmap represen...
virtual void * GetDrawContext()=0
Gets a void pointer to underlying drawing context, for the IGraphics backend See draw class implement...
int WindowWidth() const
Gets the width of the graphics context including draw scaling.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
virtual void OnRescale()
Implement to do something when graphics is scaled globally (e.g.