Fixed the clipping glitch (bug that caused the window borders and backgrounds to not be rendered).
Fixed text input bug that could cause the program to crash.
This commit is contained in:
parent
2d1ea95600
commit
2babe51576
2
demo/sfml_opengl2/build.bat
Normal file
2
demo/sfml_opengl2/build.bat
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
mingw32-make -f Makefile
|
||||||
|
pause
|
@ -25,8 +25,8 @@
|
|||||||
#include "../../nuklear.h"
|
#include "../../nuklear.h"
|
||||||
#include "nuklear_sfml_gl2.h"
|
#include "nuklear_sfml_gl2.h"
|
||||||
|
|
||||||
#define WINDOW_WIDTH 1200
|
#define WINDOW_WIDTH 800
|
||||||
#define WINDOW_HEIGHT 800
|
#define WINDOW_HEIGHT 600
|
||||||
|
|
||||||
#define MAX_VERTEX_BUFFER 512 * 1024
|
#define MAX_VERTEX_BUFFER 512 * 1024
|
||||||
#define MAX_ELEMENT_BUFFER 128 * 1024
|
#define MAX_ELEMENT_BUFFER 128 * 1024
|
||||||
@ -46,7 +46,7 @@
|
|||||||
* and the corresponding function. */
|
* and the corresponding function. */
|
||||||
//#include "../style.c"
|
//#include "../style.c"
|
||||||
//#include "../calculator.c"
|
//#include "../calculator.c"
|
||||||
//#include "../overview.c"
|
#include "../overview.c"
|
||||||
//#include "../node_editor.c"
|
//#include "../node_editor.c"
|
||||||
|
|
||||||
/* ===============================================================
|
/* ===============================================================
|
||||||
@ -54,14 +54,12 @@
|
|||||||
* DEMO
|
* DEMO
|
||||||
*
|
*
|
||||||
* ===============================================================*/
|
* ===============================================================*/
|
||||||
static void error_callback(int e, const char *d)
|
|
||||||
{printf("Error %d: %s\n", e, d);}
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
/* Platform */
|
/* Platform */
|
||||||
sf::ContextSettings settings(24, 8, 4, 2, 2);
|
sf::ContextSettings settings(24, 8, 4, 2, 2);
|
||||||
sf::Window window(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "Demo", sf::Style::Default, settings);
|
sf::Window window(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "Demo", sf::Style::Default, settings);
|
||||||
|
|
||||||
window.setVerticalSyncEnabled(true);
|
window.setVerticalSyncEnabled(true);
|
||||||
window.setActive(true);
|
window.setActive(true);
|
||||||
|
|
||||||
@ -152,7 +150,7 @@ int main(void)
|
|||||||
|
|
||||||
/* -------------- EXAMPLES ---------------- */
|
/* -------------- EXAMPLES ---------------- */
|
||||||
//calculator(ctx);
|
//calculator(ctx);
|
||||||
//overview(ctx);
|
overview(ctx);
|
||||||
//node_editor(ctx);
|
//node_editor(ctx);
|
||||||
/* ----------------------------------------- */
|
/* ----------------------------------------- */
|
||||||
|
|
||||||
@ -164,7 +162,7 @@ int main(void)
|
|||||||
nk_color_fv(bg, background);
|
nk_color_fv(bg, background);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
glClearColor(bg[0], bg[1], bg[2], bg[3]);
|
glClearColor(bg[0], bg[1], bg[2], bg[3]);
|
||||||
/* IMPORTANT: `nk_glfw_render` modifies some global OpenGL state
|
/* IMPORTANT: `nk_sfml_render` modifies some global OpenGL state
|
||||||
* with blending, scissor, face culling and depth test and defaults everything
|
* with blending, scissor, face culling and depth test and defaults everything
|
||||||
* back into a default state. Make sure to either save and restore or
|
* back into a default state. Make sure to either save and restore or
|
||||||
* reset your own state after drawing rendering the UI. */
|
* reset your own state after drawing rendering the UI. */
|
||||||
|
@ -71,13 +71,9 @@ nk_sfml_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_
|
|||||||
{
|
{
|
||||||
/* setup global state */
|
/* setup global state */
|
||||||
struct nk_sfml_device* dev = &sfml.ogl;
|
struct nk_sfml_device* dev = &sfml.ogl;
|
||||||
struct nk_vec2 scale;
|
|
||||||
|
|
||||||
sf::Vector2u window_size = sfml.window->getSize();
|
int window_width = sfml.window->getSize().x;
|
||||||
sf::Vector2u view_size = sfml.window->getSize();
|
int window_height = sfml.window->getSize().y;
|
||||||
|
|
||||||
scale.x = (float)view_size.x / (float)window_size.x;
|
|
||||||
scale.y = (float)view_size.y / (float)window_size.y;
|
|
||||||
|
|
||||||
glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT);
|
glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT);
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
@ -87,11 +83,11 @@ nk_sfml_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_
|
|||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
glViewport(0, 0, (GLsizei)view_size.x, (GLsizei)view_size.y);
|
glViewport(0, 0, (GLsizei)window_width, (GLsizei)window_height);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glOrtho(0.0f, window_size.x, window_size.y, 0.0f, -1.0f, 1.0f);
|
glOrtho(0.0f, window_width, window_height, 0.0f, -1.0f, 1.0f);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
@ -152,10 +148,10 @@ nk_sfml_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_
|
|||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, (GLuint)cmd->texture.id);
|
glBindTexture(GL_TEXTURE_2D, (GLuint)cmd->texture.id);
|
||||||
glScissor(
|
glScissor(
|
||||||
(GLint)(cmd->clip_rect.x * scale.x),
|
(GLint)(cmd->clip_rect.x),
|
||||||
(GLint)((window_size.y - (GLint)(cmd->clip_rect.y + cmd->clip_rect.h)) * scale.y),
|
(GLint)((window_height - (GLint)(cmd->clip_rect.y + cmd->clip_rect.h))),
|
||||||
(GLint)(cmd->clip_rect.w * scale.x),
|
(GLint)(cmd->clip_rect.w),
|
||||||
(GLint)(cmd->clip_rect.h * scale.y));
|
(GLint)(cmd->clip_rect.h));
|
||||||
glDrawElements(GL_TRIANGLES, (GLsizei)cmd->elem_count, GL_UNSIGNED_SHORT, offset);
|
glDrawElements(GL_TRIANGLES, (GLsizei)cmd->elem_count, GL_UNSIGNED_SHORT, offset);
|
||||||
offset += cmd->elem_count;
|
offset += cmd->elem_count;
|
||||||
}
|
}
|
||||||
@ -392,9 +388,7 @@ nk_sfml_handle_event(sf::Event* event)
|
|||||||
}
|
}
|
||||||
else if(event->type == sf::Event::TextEntered)
|
else if(event->type == sf::Event::TextEntered)
|
||||||
{
|
{
|
||||||
nk_glyph glyph;
|
nk_input_unicode(ctx, event->text.unicode);
|
||||||
memcpy(glyph, (const void*)event->text.unicode, NK_UTF_SIZE);
|
|
||||||
nk_input_glyph(ctx, glyph);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user