Thomas Kay
Thomas Kay

Reputation: 21

glfwCreateWindow(..) returns null in Visual Studio

I am using the GLFW and only want to open a empty windows.

I downloaded the GLFW for Windows 32. Created an empty console project and wrote this code:

#include "main.h"
#pragma comment (lib, "glfw3dll")
#pragma comment (lib, "OpenGL32")

#define GLFW_DLL

#include <glfw3.h>
#include <chrono>
#include <iostream>

using namespace std::chrono;


GLFWwindow* window;

bool running = true;


bool initialise(){
return true;
}

void update(double deltaTime){

}

void render(){

}



int main(int argc, char **argv) {

if (!glfwInit)
    return -1;

window = (glfwCreateWindow(800, 600, "Hello World", nullptr, nullptr));

if (window == nullptr){
    glfwTerminate();
    return -1;
}

glfwMakeContextCurrent(window);

if (!initialise()){
    glfwTerminate();
    return -1;
}

auto currentTimeStamp = system_clock::now();
auto prevTimeStamp = system_clock::now();

while (running)
{
    currentTimeStamp = system_clock::now();

    auto elapsed = duration_cast<milliseconds>(currentTimeStamp - prevTimeStamp);
    auto seconds = double(elapsed.count()) / 1000.0;

    update(seconds);

    render();

    glfwPollEvents();

    prevTimeStamp = currentTimeStamp;

}

glfwTerminate();

return -1;
}

And I think I added the library and the header correctly. But everytime the programm exits with -1 after the glfwCreateWindow(..) function, because this functions return null.

Can somebody help me?

Upvotes: 1

Views: 4428

Answers (1)

genpfault
genpfault

Reputation: 52083

if (!glfwInit)
    return -1;

I'm not sure why glfwInit would be NULL unless something truly terrible happened during DLL load.

Try calling glfwInit() instead:

if( !glfwInit() )
    return -1;

Upvotes: 3

Related Questions