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:
Ricardo Antonio Tejada 2017-02-13 01:59:32 -05:00
parent 2d1ea95600
commit 2babe51576
3 changed files with 17 additions and 23 deletions

View File

@ -0,0 +1,2 @@
mingw32-make -f Makefile
pause

View File

@ -25,8 +25,8 @@
#include "../../nuklear.h"
#include "nuklear_sfml_gl2.h"
#define WINDOW_WIDTH 1200
#define WINDOW_HEIGHT 800
#define WINDOW_WIDTH 800
#define WINDOW_HEIGHT 600
#define MAX_VERTEX_BUFFER 512 * 1024
#define MAX_ELEMENT_BUFFER 128 * 1024
@ -46,7 +46,7 @@
* and the corresponding function. */
//#include "../style.c"
//#include "../calculator.c"
//#include "../overview.c"
#include "../overview.c"
//#include "../node_editor.c"
/* ===============================================================
@ -54,14 +54,12 @@
* DEMO
*
* ===============================================================*/
static void error_callback(int e, const char *d)
{printf("Error %d: %s\n", e, d);}
int main(void)
{
/* Platform */
sf::ContextSettings settings(24, 8, 4, 2, 2);
sf::Window window(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "Demo", sf::Style::Default, settings);
window.setVerticalSyncEnabled(true);
window.setActive(true);
@ -152,7 +150,7 @@ int main(void)
/* -------------- EXAMPLES ---------------- */
//calculator(ctx);
//overview(ctx);
overview(ctx);
//node_editor(ctx);
/* ----------------------------------------- */
@ -164,7 +162,7 @@ int main(void)
nk_color_fv(bg, background);
glClear(GL_COLOR_BUFFER_BIT);
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
* back into a default state. Make sure to either save and restore or
* reset your own state after drawing rendering the UI. */

View File

@ -71,13 +71,9 @@ nk_sfml_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_
{
/* setup global state */
struct nk_sfml_device* dev = &sfml.ogl;
struct nk_vec2 scale;
sf::Vector2u window_size = sfml.window->getSize();
sf::Vector2u view_size = sfml.window->getSize();
scale.x = (float)view_size.x / (float)window_size.x;
scale.y = (float)view_size.y / (float)window_size.y;
int window_width = sfml.window->getSize().x;
int window_height = sfml.window->getSize().y;
glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT);
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);
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);
glPushMatrix();
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);
glPushMatrix();
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);
glScissor(
(GLint)(cmd->clip_rect.x * scale.x),
(GLint)((window_size.y - (GLint)(cmd->clip_rect.y + cmd->clip_rect.h)) * scale.y),
(GLint)(cmd->clip_rect.w * scale.x),
(GLint)(cmd->clip_rect.h * scale.y));
(GLint)(cmd->clip_rect.x),
(GLint)((window_height - (GLint)(cmd->clip_rect.y + cmd->clip_rect.h))),
(GLint)(cmd->clip_rect.w),
(GLint)(cmd->clip_rect.h));
glDrawElements(GL_TRIANGLES, (GLsizei)cmd->elem_count, GL_UNSIGNED_SHORT, offset);
offset += cmd->elem_count;
}
@ -392,9 +388,7 @@ nk_sfml_handle_event(sf::Event* event)
}
else if(event->type == sf::Event::TextEntered)
{
nk_glyph glyph;
memcpy(glyph, (const void*)event->text.unicode, NK_UTF_SIZE);
nk_input_glyph(ctx, glyph);
nk_input_unicode(ctx, event->text.unicode);
return 1;
}