2017-04-23 3 views
0

게임 엔진 튜토리얼을 따르려고합니다. 비디오가이 코드를 실행하면 창을 엽니 다. 내가 할 때, 그것은 창문이 만들어지지 않은 경우를 대비해서 내가 가진 오류 메시지를 준다. 이 window.cpp 내 코드입니다GLFW는 내 창을 초기화하지 않을 것입니다.

#include "window.h" 

namespace sparky { 

namespace graphics { 

    Window::Window(const char *title, int width, int height) { 
     m_Title = title; 
     m_Width = width; 
     m_Height = height; 
     if (!init()) 
      glfwTerminate(); 
    } 

    Window::~Window() 
    { 
     glfwTerminate(); 
    } 

    bool Window::init() 
    { 
     if (!glfwInit) { 
      std::cout << "Failed To Initialize" << std::endl; 
      return false; 
     } 

     m_Window = glfwCreateWindow(m_Width, m_Height, m_Title, NULL, NULL); 

     if (!m_Window) 
     { 
      std::cout << "Window Not Created" << std::endl; 
      return false; 
     } 

     glfwMakeContextCurrent(m_Window); 
     return true; 

    } 

    bool Window::closed() const 
    { 
     return glfwWindowShouldClose(m_Window); 
    } 

    void Window::update() const 
    { 
     glfwPollEvents(); 
     glfwSwapBuffers(m_Window); 
    } 

} 

} 

, 나는 여기에 내 window.h

#pragma once 
#include <GLFW/glfw3.h> 
#include <iostream> 

namespace sparky { 

namespace graphics { 

    class Window { 
    private: 
     const char* m_Title; 
     int m_Width, m_Height; 
     GLFWwindow *m_Window; 
     bool m_Closed; 
    public: 
     Window(const char* title, int width, int height); 
     ~Window(); 
     bool closed() const; 
     void update() const; 
    private: 
     bool init(); 


    }; 

} 

} 

내 주요 클래스, 윈도우가 오류 라인을 작성하지 얻을

#include <GLFW/glfw3.h> 
#include <iostream> 
#include "src/graphics/window.h" 

int main() { 

using namespace sparky; 
using namespace graphics; 

Window window("Sparks Fly", 800, 600); 

while (!window.closed()) { 
    window.update(); 
} 

system("PAUSE"); 
return 0; 
} 

답변

0

귀하 문제는 다음과 같습니다.

 if (!glfwInit) { 

Beca glfwInit을 라이브러리 함수로 사용하면 (올바르게 연결했다고 가정하면) 항상 유효한 주소가 nullptr이 아닙니다. 따라서 !glfwInit은이를 false으로 변경하고 전 세계를 돌보며 if 문을 사용합니다.

이 단순히 부울 값으로 변환하지 함수를 호출하여 고정 할 수 있습니다

 if(!glfwInit()) { 
+0

가 sooo를 감사, 나는 한혜진 오랫동안이 문제를 해결하려고했다! – NYBoss00

+0

문제 없습니다! :디 – InternetAussie

관련 문제