VS2019 says that GLFWwindow* is not initialized. It says it as a warning and then does not compile. Also it worked before and it says it only in the start_window function.
...main.cpp(19): error C4700: uninitialized local variable 'window' used
...Done building project "CityEngine.vcxproj" -- FAILED.
I tried: (Advice from BDL) To initialize it with nullptr - invisible and unresponsive window. (VS IntelliSense) To do window{}. Same result.
I have "Treat warnings as errors" off.
main.cpp
#include "city/stdheader.h"
#include "city/city.h"
//Target board :)
//put colors in front of stuff (thanks stack overflow)
float color1[3] = { 1.0, 1.0, 1.0 };
float color2[3] = { 1.0, 0.0, 0.0 };
float colorA[3] = { 0.3, 0.3, 0.3 };
float vertices1[8] = { 0.9, 0.9, -0.9, 0.9, -0.9, -0.9, 0.9, -0.9 };
float vertices2[8] = { 0.7, 0.7, -0.7, 0.7, -0.7, -0.7, 0.7, -0.7 };
float vertices3[8] = { 0.5, 0.5, -0.5, 0.5, -0.5, -0.5, 0.5, -0.5 };
float vertices4[8] = { 0.3, 0.3, -0.3, 0.3, -0.3, -0.3, 0.3, -0.3 };
float vertices5[8] = { 0.1, 0.1, -0.1, 0.1, -0.1, -0.1, 0.1, -0.1 };
float vertices1A[6] = { 0, 0, -0.2, 0.2, -0.2, -0.1 };
float vertices2A[6] = { -0.4, 0.3, -0.6, 0.5, -0.6, 0.2 };
float vertices3A[6] = { 0.4, -0.6, 0.2, -0.4, 0.2, -0.7 };
int main() {
glfwInit();
GLFWwindow* window;
City::start_window(window, 680, 480);
while (!CtWINDOW_OPEN(window)) {
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(1.0, 1.0, 1.0, 1.0);
City::drawpoly(vertices1, color2);
City::drawpoly(vertices2, color1);
City::drawpoly(vertices3, color2);
City::drawpoly(vertices4, color1);
City::drawpoly(vertices5, color2);
//Arrows
City::drawtriangle(vertices1A, colorA);
City::drawtriangle(vertices2A, colorA);
City::drawtriangle(vertices3A, colorA);
CtPROCESS(window);
}
glfwTerminate();
}
cityengine.cpp
#include "stdheader.h"
#include "city.h"
#include <GLFW/glfw3.h>
namespace City {
void terminate_window() {
glfwTerminate();
}
void start_window(GLFWwindow* window, float width, float height) {
glfwInit();
window = glfwCreateWindow(width, height, "CITYEngine", 0, 0);
glfwMakeContextCurrent(window);
if (!window)
{
terminate_window();
}
//while (!WINDOW_OPEN(CITYwindow)) {
// PROCESS(CITYwindow);
// }
}
void drawpoly(float vertices[8], float color[3]) {
glBegin(GL_POLYGON);
glColor3f(color[0], color[1], color[2]);
glVertex2f(vertices[0], vertices[1]);
glVertex2f(vertices[2], vertices[3]);
glVertex2f(vertices[4], vertices[5]);
glVertex2f(vertices[6], vertices[7]);
glEnd();
}
void drawtriangle(float vertices[6], float color[3]) {
glBegin(GL_TRIANGLES);
glColor3f(color[0], color[1], color[2]);
glVertex2f(vertices[0], vertices[1]);
glVertex2f(vertices[2], vertices[3]);
glVertex2f(vertices[4], vertices[5]);
glEnd();
}
}
city.h
#pragma once
#define CtWINDOW_OPEN(window) glfwWindowShouldClose(window)
#define CtPROCESS(window) glfwSwapBuffers(window); glfwPollEvents()
namespace City {
void start_window(GLFWwindow* window, float width, float height);
void terminate_window();
void drawpoly(float vertices[8], float color[3]);
void drawtriangle(float vertices[6], float color[3]);
}
stdheader (probably not needed for this question but im going to include it anyway)
#pragma once
#include <iostream>
#include <GLFW/glfw3.h>
using std::string;
using std::cout;
using std::cin;
Any clue?
PS. Do anyone know why?