AudioGoose45
Topic Author
Posts: 1
Joined: 22 Jun 2019, 18:14

GLFW and Noesis Integration; no display in GLFW window

01 Jul 2019, 02:54

So I've been playing around with Noesis on a side project that I've working on for quite a while now. I've been able to put together my game engine that is written in C++ and with GLFW and GLAD. The engine by itself works thus far without issue. So I began to integrate Noesis into the project following the Integration Sample for GLUT, replacing the GLUT calls with the related GLFW calls.

Right now what is happening is the application starts, but I'm presented only with a blue screen and not the Noesis display. So, my assumption is that I'm missing a step somewhere. The question that I have it what am I missing?

Below I have some of the functions calls supplied that involve rendering and houses all of the Noesis calls.

void Mongoose::Engine::RenderTask::Run () {

	//If the renderer is not initialized, then we need to initialize it.
	if (!Initalized) {
		InitializeRenderer ();
		Initalized = true;
	}

	if (!glfwWindowShouldClose (window)) {

		if (glfwGetKey (window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
			glfwSetWindowShouldClose (window, true);

		// Update view (layout, animations, ...)
		_view->Update (glfwGetTimerValue () / 1000.0);

		// Offscreen rendering phase populates textures needed by the on-screen rendering
		_view->GetRenderer ()->UpdateRenderTree ();
		_view->GetRenderer ()->RenderOffscreen ();

		glBindFramebuffer (GL_FRAMEBUFFER, 0);

		int width, height;
		glfwGetFramebufferSize (window, &width, &height);
		glViewport (0, 0, width, height);

		glClearColor (0.0f, 0.0f, 0.25f, 0.0f);
		glClearStencil (0);
		glClear (GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

		// Rendering is done in the active framebuffer
		_view->GetRenderer ()->Render ();

		/* Swap front and back buffers */
		glfwSwapBuffers (window);

		/* Poll for and process events */
		glfwPollEvents ();

	}
	else {
		TerminateRenderer ();
	}
}

bool Mongoose::Engine::RenderTask::InitializeRenderer () {

	//Initialize GLFW
	if (!glfwInit ()) {
		return false;
	}

	else {



		int width = Configuration->GetResolutionX ();
		int height = Configuration->GetResolutionY ();

		//Set the GLFW version features.
		glfwWindowHint (GLFW_CONTEXT_VERSION_MAJOR, 3);
		glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, 3);
		glfwWindowHint (GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

		//Create a GLFW window.
		if (Configuration->GetFullScreen ()) {
			window = glfwCreateWindow (width, height, "LearnOpenGL", glfwGetPrimaryMonitor (), NULL);
		}
		else {
			window = glfwCreateWindow (width, height, "LearnOpenGL", NULL, NULL);
		}
		if (window == NULL) {
			LogFile->LogError ("Failed to create GLFW window");
			TerminateRenderer ();
			return false;
		}

		//Make the new window the current context.
		glfwMakeContextCurrent (window);
		gladLoadGL ();
		glfwSwapInterval (1);

		//Set the viewpoint
		//glViewport (0, 0, width, height);

		InitializeNoesis ();

		return true;
	}


}

void Mongoose::Engine::RenderTask::InitializeNoesis () {

	auto logHandler = [](const char*, uint32_t, uint32_t level, const char*, const char* message) {
		// [TRACE] [DEBUG] [INFO] [WARNING] [ERROR]
		const char* prefixes[] = { "T", "D", "I", "W", "E" };
		printf ("[NOESIS/%s] %s\n", prefixes[level], message);
	};

	Noesis::GUI::Init (nullptr, logHandler, nullptr);

	// For simplicity purposes we are not using resource providers in this sample. ParseXaml() is
	// enough if there is no extra XAML dependencies
	Noesis::Ptr<Noesis::Grid> xaml (Noesis::GUI::ParseXaml<Noesis::Grid> (R"(
        <Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
            <Grid.Background>
                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                    <GradientStop Offset="0" Color="#FF123F61"/>
                    <GradientStop Offset="0.6" Color="#FF0E4B79"/>
                    <GradientStop Offset="0.7" Color="#FF106097"/>
                </LinearGradientBrush>
            </Grid.Background>
            <Viewbox>
                <StackPanel Margin="50">
                    <Button Content="Hello World!" Margin="0,30,0,0"/>
                    <Rectangle Height="5" Margin="-10,20,-10,0">
                        <Rectangle.Fill>
                            <RadialGradientBrush>
                                <GradientStop Offset="0" Color="#40000000"/>
                                <GradientStop Offset="1" Color="#00000000"/>
                            </RadialGradientBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                </StackPanel>
            </Viewbox>
        </Grid>
    )"));

	// View creation to render and interact with the user interface
	// We transfer the ownership to a global pointer instead of a Ptr<> because there is no way
	// in GLUT to do shutdown and we don't want the Ptr<> to be released at global time
	_view = Noesis::GUI::CreateView (xaml).GiveOwnership ();
	_view->SetIsPPAAEnabled (true);

	//Get the device from Noesis
	Noesis::Ptr<Noesis::RenderDevice> device = NoesisApp::GLFactory::CreateDevice ();

	// Renderer initialization with an OpenGL device
	_view->GetRenderer ()->Init (device);

}
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: GLFW and Noesis Integration; no display in GLFW window

01 Jul 2019, 11:06

Hello, I think you are missing the resize code:
static void ReshapeFunc(int width, int height)
{
    _view->SetSize(width, height);
}
Without that the View has a default size of 0,0 and nothing would be rendered.

Who is online

Users browsing this forum: Semrush [Bot] and 80 guests