GLFW3 & Noesis
I've been trying to get a Noesis on GLFW3 application running without any success so far. I took the GLFW triangle.c sample from GLFW3's repository and copied some of the code from the GLUT sample in what I hope is the correct way.
The code crashes on the "Update Renderer logic". If I comment out that section, I get the spinning triangle.
error.log exists and is empty and NS.Log.<username>.log shows a bunch of asset loads. The assets are properly in place, since I have an #ifdefed alternative GLUT build with the sample program which builds and works correctly (spinning cube with GUI).
The code follows (built on VS 2012):
Any clues as to what I might be doing wrong? Also, any chance of a minimal GLFW sample with Noesis (probably 2.x)?
Thanks!
The code crashes on the "Update Renderer logic". If I comment out that section, I get the spinning triangle.
error.log exists and is empty and NS.Log.<username>.log shows a bunch of asset loads. The assets are properly in place, since I have an #ifdefed alternative GLUT build with the sample program which builds and works correctly (spinning cube with GUI).
The code follows (built on VS 2012):
Code: Select all
#include <Windows.h>
#define GLFW_INCLUDE_GLU
#include <GL/glfw3.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#pragma warning(disable: 4275)
#pragma warning(disable: 4251)
#define NOESIS_GUI
#ifdef NOESIS_GUI
#include <Noesis.h>
#include <NsCore/Kernel.h>
#include <NsCore/Error.h>
#include <NsCore/NsSystem.h>
#include <NsCore/NsConfig.h>
#include <NsRender/IRenderTarget2D.h> // < falta en IGLRenderSystem
#include <NsRender/IGLRenderSystem.h>
#include <NsResource/IResourceSystem.h>
#include <NsDrawing/IVGLSurface.h>
#include <NsDrawing/IVGLSystem.h>
#include <NsGui/IUIResource.h>
#include <NsGui/Visual.h>
#include <NsGui/IRenderer.h>
#include <NsGui/Slider.h>
#include <NsGui/ComboBox.h>
#include <NsGui/RoutedEvent.h>
#include <NsGui/VisualTreeHelper.h>
using namespace Noesis;
using namespace Noesis::Core;
using namespace Noesis::Gui;
using namespace Noesis::Resource;
using namespace Noesis::Render;
using namespace Noesis::Drawing;
Ptr<IRenderer> gUIRenderer;
Ptr<UIElement> gUIRoot;
#endif
clock_t _startclock;
//#pragma comment(lib, "GLFWDLL.lib")
#ifdef NDEBUG
#pragma comment(lib, "GLFW3.lib")
#else
#pragma comment(lib, "GLFW3_D.lib")
#endif
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#ifdef NOESIS_GUI
#pragma comment(lib, "Noesis.lib")
#endif
#ifdef NOESIS_GUI
void ErrorHandler(const NsChar* filename, NsInt line, const NsChar* desc)
{
printf("\nERROR: %s\n\n", desc);
exit(1);
}
void Shutdown(void)
{
// Free global resources and shutdown kernel
gUIRoot.Reset();
gUIRenderer.Reset();
NsGetKernel()->Shutdown();
}
#endif
static void error_callback(int error, const char* description)
{
fprintf(stderr, "Error: %s\n", description);
}
int main(void)
{
int width, height, x;
GLFWwindow* window;
glfwSetErrorCallback(error_callback);
// Initialise GLFW
if (!glfwInit())
exit(EXIT_FAILURE);
// Open a window and create its OpenGL context
window = glfwCreateWindow(640, 480, "Spinning Triangle", NULL, NULL);
if (!window)
{
glfwTerminate();
exit(EXIT_FAILURE);
}
_startclock = clock();
// Enable vertical sync (on cards that support it)
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
#ifdef NOESIS_GUI
{
// Install an error handler to catch any problem with NoesisGui
Noesis::Core::SetErrorHandler(ErrorHandler);
// Force the OpenGL renderer
NsConfigValue("Render.RenderSystem", "Render", "GL");
// Launch Noesis Kernel
NsGetKernel()->Init();
// Create a OpenGL context that will be used by NoesisGui.
HDC hDC = wglGetCurrentDC();
IGLRenderSystem::SetContext(hDC, wglCreateContext(hDC));
NsGetKernel()->InitSystems();
// Load the .xaml resource
Ptr<IUIResource> guiResource = NsDynamicCast< Ptr<IUIResource> >(NsGetSystem<IResourceSystem>()->Load("Gui/Samples/SDKTutorial/UIgl.xaml"));
gUIRoot.Reset(NsStaticCast<UIElement*>(guiResource->GetRoot()));
// Create the UI renderer
gUIRenderer = CreateRenderer(gUIRoot.GetPtr());
gUIRenderer->SetSurfaceClearMode(Noesis::Gui::SurfaceClearMode_Manual);
gUIRenderer->SetAntialiasingMode(Noesis::Gui::AntialiasingMode_PPAA);
atexit(Shutdown);
}
#endif
// Ensure we can capture the escape key being pressed below
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
for (;;)
{
double t = glfwGetTime();
glfwGetCursorPos(window, &x, NULL);
// Get window size (may be different than the requested size)
glfwGetWindowSize(window, &width, &height);
// Special case: avoid division by zero below
height = height > 0 ? height : 1;
glViewport(0, 0, width, height);
// Clear color buffer to black
glClearColor(0.f, 0.f, 0.f, 0.f);
glClear(GL_COLOR_BUFFER_BIT);
// Select and setup the projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(65.f, (GLfloat) width / (GLfloat) height, 1.f, 100.f);
// Select and setup the modelview matrix
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
gluLookAt(0.f, 1.f, 0.f, // Eye-position
0.f, 20.f, 0.f, // View-point
0.f, 0.f, 1.f); // Up-vector
// Draw a rotating colorful triangle
glTranslatef(0.f, 14.f, 0.f);
glRotatef(0.3f * (GLfloat) x + (GLfloat) t * 100.f, 0.f, 0.f, 1.f);
glBegin(GL_TRIANGLES);
glColor3f(1.f, 0.f, 0.f);
glVertex3f(-5.f, 0.f, -4.f);
glColor3f(0.f, 1.f, 0.f);
glVertex3f(5.f, 0.f, -4.f);
glColor3f(0.f, 0.f, 1.f);
glVertex3f(0.f, 0.f, 6.f);
glEnd();
#ifdef NOESIS_GUI
// Tick kernel
NsGetKernel()->Tick();
// Update renderer
gUIRenderer->Update(float(clock() - _startclock)/ 1000.0f);
// ...Do something useful here because Update() is concurrent...
RenderCommands* commands = gUIRenderer->WaitForUpdate();
// Render
glClearStencil(1);
glClear(GL_STENCIL_BUFFER_BIT);
gUIRenderer->Render(commands);
// ...Do something useful here because Render() is concurrent...
gUIRenderer->WaitForRender();
#endif
// Swap buffers
glfwSwapBuffers(window);
glfwPollEvents();
// Check if the ESC key was pressed or the window should be closed
if (glfwGetKey(window, GLFW_KEY_ESCAPE))
break;
if (glfwGetWindowParam(window, GLFW_SHOULD_CLOSE))
break;
}
// Close OpenGL window and terminate GLFW
glfwTerminate();
exit(EXIT_SUCCESS);
}
Thanks!
Re: GLFW3 & Noesis
A few things,
- Could you confirm us that the SpinningCube sample we provide is working for you?
- Could you attach the NS.Log<username>.log file?
Re: GLFW3 & Noesis
Sorry for the delay. I am currently traveling and don't have access to my desktop.
The spinning cube does indeed build and work for me with Noesis appropriately layered on top. I'll get back to you probably after Monday with the log.
The spinning cube does indeed build and work for me with Noesis appropriately layered on top. I'll get back to you probably after Monday with the log.
Re: GLFW3 & Noesis
Attached is the log. I didn't see anything specific in there, but your mileage might vary.
Thanks!
Thanks!
- Attachments
-
- NsLog.zip
- (18.04 KiB) Downloaded 453 times
Re: GLFW3 & Noesis
I don't see any suspicious line in the attached log.
I see that you are installing an error handler to catch noesis error. Are you getting any information from that function?
Whenever I have time I will try to test the wrapper on my machine.
Thanks!
I see that you are installing an error handler to catch noesis error. Are you getting any information from that function?
Whenever I have time I will try to test the wrapper on my machine.
Thanks!
Re: GLFW3 & Noesis
Nah, if the error handler were called I would have a warning in the log. The problem seems to be in another part, could you describe more about the crash you are getting? (kind of crash, etc)
Re: GLFW3 & Noesis
Code: Select all
gUIRenderer->Update(float(clock() - _startclock)/ 1000.0f);
// ...Do something useful here because Update() is concurrent...
RenderCommands* commands = gUIRenderer->WaitForUpdate(); // crash occurs on this line
Unhandled exception at 0x775F016E (ntdll.dll) in noesistest.exe: 0x00000000: The operation completed successfully.
-
-
sfernandez
Site Admin
- Posts: 3222
- Joined:
Re: GLFW3 & Noesis
I think you forgot to create and set the surface where GUI is renedered.
After creating GUI IRenderer, you must create a valid IVGLSurface wrapping the current window FBO (should be 0 in your sample):
Hope it helps 
After creating GUI IRenderer, you must create a valid IVGLSurface wrapping the current window FBO (should be 0 in your sample):
Code: Select all
Ptr<IRenderTarget2D> rt = NsGetSystem<IGLRenderSystem>()->WrapRenderTarget(GLuint(0), width, height);
Ptr<IVGLSurface> surface = NsGetSystem<IVGLSystem>()->CreateSurface(rt.GetPtr());
gUIRenderer->SetSurface(surface.GetPtr());

Re: GLFW3 & Noesis
Thanks, that was it! Adding those lines in got me a working spinning triangle with GLFW3 and the Noesis GUI overlay.
Who is online
Users browsing this forum: No registered users and 4 guests