VS错误E1696,第一次使用openGL开发

时间:2018-03-11 15:42:25

标签: c++ visual-studio

错误讯息:

严重级代码说明项目文件行抑制状态 错误(活动)E1696无法打开源文件" stdafx.h" Twitch c:\ Users \ PC \ source \ repos \ Twitch \ Twitch \ Engine \ Engine.h 1

代码是

#include "stdafx.h"
#ifndef TWITCH_ENGINE
#define TWITCH_ENGINE


#include "GLFW\glfw3.h"
#pragma comment (lib, "opengl32.lib")
#include<iostream>
using namespace std;

class Engine {
public:
    static int SCREEN_WIDTH;
    static int SCREEN_HEIGHT;

    Engine();
    ~Engine();

    bool Initialize(char* windowTitle);

    void Update();
    void Render();

private:
    static GLFWwindow* window;
};

#endif

并在Twitch.cpp中:

#include "Engine.h"

int Engine::SCREEN_WIDTH = 1024;
int Engine::SCREEN_HEIGHT = 768;
GLFWwindow* Engine::window = NULL;

Engine::Engine() {

}

Engine::~Engine() {

}

bool Engine::Initialize(char* windowTitle) {
    if (!glfwInit()) {
        cout << "Error initalizing GLFW" << endl;
        return false;
    }

    window = glfwCreateWindow(SCREEN_WIDTH, SCREEN_HEIGHT, windowTitle, NULL, NULL);
    if (window == NULL) {
        cout << "Error creating window" << endl;
        return false;
    }

    //OpenGL Setup
    glfwMakeContextCurrent(window);
    int width, height;
    glfwGetFramebufferSize(window, &width, &height);
    glfwSwapInterval(1);

    const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    int xPos = (mode->width - SCREEN_WIDTH) / 2;
    int yPos = (mode->height - SCREEN_HEIGHT) / 2;

    glfwSetWindowPos(window, xPos, yPos);

    //GL setup
    //Viewport
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, width, 0, height, -10, 10);
    glDepthRange(-10, 10);
    glMatrixMode(GL_MODELVIEW);

    //Alpha Blending
    glEnable(GL_ALPHA_TEST);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    return true;
}

void Engine::Update() {
    glfwPollEvents();

}

void Engine::Render() {
    glClearColor(0, 1, 0, 1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);



    glfwSwapBuffers(window);

}

该文件已包含在我的main.cpp文件中。 问题和解决方案的原因是什么?

0 个答案:

没有答案