Skip to content
This repository has been archived by the owner on Dec 2, 2019. It is now read-only.

GLFW adapter not drawing Properly #920

Open
fishingGrapes opened this issue Oct 7, 2019 · 1 comment
Open

GLFW adapter not drawing Properly #920

fishingGrapes opened this issue Oct 7, 2019 · 1 comment

Comments

@fishingGrapes
Copy link

I am using the glfw-opengl4 demo to draw. I don't get any compile errors. But the windows are not drawing properly.
Here is the Image

Code:

ImGuiLayer.h

#pragma once

#define NK_GLFW_GL4_IMPLEMENTATION
#define NK_UINT_DRAW_INDEX
#define NK_INCLUDE_FIXED_TYPES
#define NK_INCLUDE_STANDARD_IO
#define NK_INCLUDE_STANDARD_VARARGS
#define NK_INCLUDE_DEFAULT_ALLOCATOR
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
#define NK_INCLUDE_FONT_BAKING
#define NK_INCLUDE_DEFAULT_FONT
#define NK_KEYSTATE_BASED_INPUT

#include "Atlas/Layer.h"

struct nk_context;
struct nk_image;

namespace atlas
{
	class CImGuiLayer : public CLayer
	{
	private:
	        ...
		nk_context* ctx;
		struct nk_image* img;
	};
}

ImGuiLayer.cpp

#include "atpch.h"
#include "ImGuiLayer.h"

...

#include "GLFW/glfw3.h"
#include "glad/glad.h"

#include "nuklear.h"
#include "demo/glfw_opengl4/nuklear_glfw_gl4.h"

#define MAX_VERTEX_BUFFER 512 * 1024
#define MAX_ELEMENT_BUFFER 128 * 1024

	...

	void CImGuiLayer::OnAttach( )
	{
		GLFWwindow* window = static_cast<GLFWwindow*>( m_Window->GetNativeWindow( ) );
		ctx = nk_glfw3_init( window, NK_GLFW3_INSTALL_CALLBACKS, MAX_VERTEX_BUFFER, MAX_ELEMENT_BUFFER );

		struct nk_font_atlas* atlas;
		nk_glfw3_font_stash_begin( &atlas );
		nk_glfw3_font_stash_end( );

		int tex_index = 0;
		enum
		{
			tex_width = 256, tex_height = 256
		};
		char pixels[ tex_width * tex_height * 4 ];
		memset( pixels, 128, sizeof( pixels ) );
		tex_index = nk_glfw3_create_texture( pixels, tex_width, tex_height );
		auto _img = nk_image_id( tex_index );

		img = new struct nk_image( );
		img->handle = _img.handle;
		img->w = _img.w;
		img->h = _img.h;
		for (size_t i = 0; i < 4; ++i)
			img->region[ i ] = _img.region[ i ];


	}

	void CImGuiLayer::OnDetach( )
	{
		delete img;
		nk_glfw3_shutdown( );
	}

 CImGuiLayer::OnRender( double_t alphaTime, double_t deltaTime )
	{
		nk_glfw3_new_frame( );

		enum
		{
			EASY, HARD
		};
		static int op = EASY;
		static float value = 0.6f;
		static int i = 20;

		if (nk_begin( ctx, "Show", nk_rect( 50, 50, 220, 220 ),
					  NK_WINDOW_BORDER | NK_WINDOW_MOVABLE | NK_WINDOW_CLOSABLE ))
		{
			/* fixed widget pixel width */
			nk_layout_row_static( ctx, 30, 80, 1 );
			if (nk_button_label( ctx, "button" ))
			{
				/* event handling */
			}

			/* fixed widget window ratio width */
			nk_layout_row_dynamic( ctx, 30, 2 );
			if (nk_option_label( ctx, "easy", op == ( int) EASY )) op = EASY;
			if (nk_option_label( ctx, "hard", op == ( int) HARD )) op = HARD;

			/* custom widget pixel width */
			nk_layout_row_begin( ctx, NK_STATIC, 30, 2 );
			{
				nk_layout_row_push( ctx, 50 );
				nk_label( ctx, "Volume:", NK_TEXT_LEFT );
				nk_layout_row_push( ctx, 110 );
				nk_slider_float( ctx, 0, &value, 1.0f, 0.1f );
			}
			nk_layout_row_end( ctx );
		}
		nk_end( ctx );

		/* Bindless Texture */
		if (nk_begin( ctx, "Texture", nk_rect( 250, 150, 230, 250 ),
					  NK_WINDOW_BORDER | NK_WINDOW_MOVABLE | NK_WINDOW_SCALABLE |
					  NK_WINDOW_MINIMIZABLE | NK_WINDOW_TITLE ))
		{
			struct nk_command_buffer* canvas = nk_window_get_canvas( ctx );
			struct nk_rect total_space = nk_window_get_content_region( ctx );
			nk_draw_image( canvas, total_space, img, nk_white );
		}
		nk_end( ctx );

		nk_glfw3_render( NK_ANTI_ALIASING_ON );

	}
@hbiblia
Copy link

hbiblia commented Oct 24, 2019

Prueba la versión glfw_opengl3 y glfw_opengl4 oficial en la carpeta demo y escriba los resultados.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants