I want something to show up in the window while my resources are loading.
So this is what I have in my thread:
#pragma once
#define GLEW_STATIC
#include "GL/glew.h"
#include "GLFW/glfw3.h"
#include "ShaderProgram.h"
#include "Texture2D.h"
namespace Alt {
bool RenContinue = true;
GLFWwindow* AltWindow = NULL;
ShaderProgram passShad;
void renLoop() {
float theLine = 0;
Texture2D capTex;
capTex.loadTexture("Textures/caption.png");
GLfloat scrnVertices[] = {
// position // tex coords
-1.0f, 1.0f, 0.0f, 0.0f, 1.0f, // Top left
1.0f, 1.0f, 0.0f, 1.0f, 1.0f, // Top right
1.0f, -1.0f, 0.0f, 1.0f, 0.0f, // Bottom right
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f // Bottom left
};
GLuint scrnIndices[] = {
0, 3, 2, // First Triangle
0, 2, 1 // Second Triangle
};
GLuint svbo, sibo, svao;
glGenBuffers(1, &svbo); // Generate an empty vertex buffer on the GPU
glBindBuffer(GL_ARRAY_BUFFER, svbo); // "bind" or set as the current buffer we are working with
glBufferData(GL_ARRAY_BUFFER, sizeof(scrnVertices), scrnVertices, GL_STATIC_DRAW); // copy the data from CPU to GPU
glGenVertexArrays(1, &svao); // Tell OpenGL to create new Vertex Array Object
glBindVertexArray(svao); // Make it the current one
// Position attribute
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)(0));
glEnableVertexAttribArray(0);
// Texture Coord attribute
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
glEnableVertexAttribArray(1);
// Set up index buffer
glGenBuffers(1, &sibo); // Create buffer space on the GPU for the index buffer
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, sibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(scrnIndices), scrnIndices, GL_STATIC_DRAW);
glBindVertexArray(0);
glClearColor(.5, .5, 1, 1);
double deltaTime;
double lastTime = glfwGetTime();
while (RenContinue && !glfwWindowShouldClose(AltWindow)) {
glfwPollEvents();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
double currentTime = glfwGetTime();
deltaTime = currentTime - lastTime;
lastTime = currentTime;
passShad.use();
passShad.setUniformSampler("texSampler1", 0);
passShad.setUniform("lineStart", theLine);
capTex.bind(0);
glBindVertexArray(svao);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
capTex.unbind(0);
theLine += deltaTime * .25;
if (theLine > 1) theLine = 0;
glfwSwapBuffers(AltWindow);
}
}
}
The ‘AltWindow’ has been loaded from my main thread and is defined. All I see is a black window.