trulystupidnewb wrote on Wednesday, December 01, 2010:
Hello. I’m having a bit of trouble with passing a function pointer from a
function parameter into glfwSetWindowSizeCallback. I’ve been trying to do it
for about 5 hours. I’m running VC++ 2010 under both Window XP (one computer)
and Windows 7 (another computer).
I’m trying to pass this function:
// declaration
static void GLFWCALL Resize(int width, int height);
// definition
void GLFWCALL TestGame::Resize(int width, int height)
{
glViewport(0, 0, width, height); // Sets the viewport to fit the size of the
new window
glMatrixMode(GL_PROJECTION); // Prepare to set up the projection matrix
glLoadIdentity(); // First reset the matrix
// Then calculate new projection matrix
gluPerspective(45.0f, // angle of view
(float)width/height, // screen aspect ratio
5.0f, // near plane for drawing cutoff
600.0f); // far plane for drawing cutoff
glMatrixMode(GL_MODELVIEW); // Now switch back to the modelview matrix
glLoadIdentity(); // Reset it and we are ready to draw
}
through this function:
// declaration
void SetResizeFunction(void (*resizeFunction) (int, int));
//definition
void GlfwWindow::SetResizeFunction(void (*resizeFunction) (int, int))
{
glfwSetWindowSizeCallback((GLFWwindowsizefun)resizeFunction);
}
and calling it like this:
#include “TestGame.h”
#include “GlfwWindow.h”
#include “TWInput.h”
#include
#include
std::auto_ptr g_glfwWindow;
std::auto_ptr g_TWInput;
std::auto_ptr g_TWGame;
int main()
{
try
{
g_glfwWindow = GlfwWindow::CreateGlfwWindow(“Star Sema”, 800, 600);
g_glfwWindow->SetResizeFunction(TestGame::Resize);
g_glfwWindow->SetCloseFunction(TestGame::Close);
g_TWInput = TWInput::CreateTWInput();
g_TWGame = TestGame::CreateGame();
double deltaTime = 0.0;
while ( g_TWGame->IsRunning() )
{
deltaTime = g_glfwWindow->GetElapsedSeconds();
g_TWGame->Update(deltaTime);
g_TWGame->Render();
g_glfwWindow->SwapBuffers();
}
}
catch(std::string errorMessage)
{
std::cout << errorMessage << std::endl;
}
return 0;
}
The SetCloseFunction works. However, the SetResizeFunction throws “Unhandled
exception at 0x00000258 in Barebones.exe: 0xC0000005: Access violation.”
This is truly mysterious because both functions are written similarily but one
works and the other doesnt:
this works:
void GlfwWindow::SetCloseFunction(int (*closeFunction) (void))
{
glfwSetWindowCloseCallback((GLFWwindowclosefun)closeFunction);
}
does anyone have any suggestions on passing GLFWwindowsizefun as a param?
Thanks in advance!