Hi, I want to render a skybox to an FBO with an attached cubemap texture and a per pixel linked list but when I don’t use a per pixel linked list, my skybox is drawn to the FBO but when I want to use a per pixel linked list, nothing is drawn so I’ve a black cube.
Here is the code :
// Defines several possible options for camera movement. Used as abstraction to stay away from window-system specific input methods
Matrix4f glmToODFAEGMatrix(glm::mat4 mat);
// settings
const unsigned int SCR_WIDTH = 800;
const unsigned int SCR_HEIGHT = 600;
// camera
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
Camera camera2;
float lastX = (float)SCR_WIDTH / 2.0;
float lastY = (float)SCR_HEIGHT / 2.0;
bool firstMouse = true;
// timing
float deltaTime = 0.0f;
float lastFrame = 0.0f;
int main(int argc, char* argv[])
{
/*EXPORT_CLASS_GUID(BoundingVolumeBoundingBox, BoundingVolume, BoundingBox)
EXPORT_CLASS_GUID(EntityTile, Entity, Tile)
EXPORT_CLASS_GUID(EntityTile, Entity, BigTile)
EXPORT_CLASS_GUID(EntityWall, Entity, g2d::Wall)
EXPORT_CLASS_GUID(EntityDecor, Entity, g2d::Decor)
EXPORT_CLASS_GUID(EntityAnimation, Entity, Anim)
EXPORT_CLASS_GUID(EntityHero, Entity, Hero)
EXPORT_CLASS_GUID(EntityMesh, Entity, Mesh)
MyAppli app(sf::VideoMode(800, 600), "Test odfaeg");
return app.exec();*/
// create the window
sf::Window window(sf::VideoMode(800, 600), "OpenGL", sf::Style::Default, sf::ContextSettings(24, 0, 4, 4, 6));
glewInit();
window.setVerticalSyncEnabled(true);
// activate the window
window.setActive(true);
// load resources, initialize the OpenGL states, ...
glEnable(GL_DEPTH_TEST);
// build and compile shaders
// -------------------------
const std::string cubeMapsVS = R"(#version 460
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;
out vec3 Normal;
out vec3 Position;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main()
{
Normal = mat3(transpose(inverse(model))) * aNormal;
Position = vec3(model * vec4(aPos, 1.0));
gl_Position = projection * view * model * vec4(aPos, 1.0);
}
)";
const std::string cubeMapsFS = R"(#version 460
out vec4 FragColor;
in vec3 Normal;
in vec3 Position;
uniform vec3 cameraPos;
uniform samplerCube skybox;
void main()
{
vec3 I = normalize(Position - cameraPos);
vec3 R = reflect(I, normalize(Normal));
FragColor = vec4(texture(skybox, R).rgb, 1.0);
}
)";
const std::string skyboxVS = R"(#version 460
layout (location = 0) in vec3 aPos;
out vec3 TexCoords;
uniform mat4 projection;
uniform mat4 view;
void main()
{
TexCoords = aPos;
vec4 pos = projection * view * vec4(aPos, 1.0);
gl_Position = pos.xyww;
}
)";
const std::string skyboxFS = R"(#version 460
out vec4 FragColor;
in vec3 TexCoords;
uniform samplerCube skybox;
void main()
{
FragColor = texture(skybox, TexCoords);
}
)";
const std::string perPixelLinkedListP2VS = R"(#version 460 core
layout (location = 0) in vec3 position;
uniform mat4 projection;
uniform mat4 view;
uniform mat4 model;
void main () {
gl_Position = projection * view * model * vec4(position, 1.f);
})";
const std::string perPixelLinkedListP1FS = R"(#version 460 core
struct NodeType {
vec4 color;
float depth;
uint next;
};
layout(binding = 0, offset = 0) uniform atomic_uint nextNodeCounter;
layout(binding = 0, r32ui) uniform uimage2D headPointers;
layout(binding = 0, std430) buffer linkedLists {
NodeType nodes[];
};
uniform uint maxNodes;
uniform samplerCube skybox;
in vec3 TexCoords;
layout (location = 0) out vec4 fcolor;
void main() {
uint nodeIdx = atomicCounterIncrement(nextNodeCounter);
vec4 color = texture(skybox, TexCoords);
if (nodeIdx < maxNodes) {
uint prevHead = imageAtomicExchange(headPointers, ivec2(gl_FragCoord.xy), nodeIdx);
nodes[nodeIdx].color = color;
nodes[nodeIdx].depth = gl_FragCoord.z;
nodes[nodeIdx].next = prevHead;
}
fcolor = vec4(0, 0, 0, 0);
})";
const std::string perPixelLinkedListP2FS =
R"(
#version 460
#define MAX_FRAGMENTS 5
struct NodeType {
vec4 color;
float depth;
uint next;
};
layout(binding = 0, r32ui) uniform uimage2D headPointers;
layout(binding = 0, std430) buffer linkedLists {
NodeType nodes[];
};
layout(location = 0) out vec4 fcolor;
void main() {
NodeType frags[MAX_FRAGMENTS];
int count = 0;
uint n = imageLoad(headPointers, ivec2(gl_FragCoord.xy)).r;
while( n != 0xffffffffu && count < MAX_FRAGMENTS) {
frags[count] = nodes[n];
n = frags[count].next;
count++;
}
//merge sort
int i, j1, j2, k;
int a, b, c;
int step = 1;
NodeType leftArray[MAX_FRAGMENTS/2]; //for merge sort
while (step <= count)
{
i = 0;
while (i < count - step)
{
////////////////////////////////////////////////////////////////////////
//merge(step, i, i + step, min(i + step + step, count));
a = i;
b = i + step;
c = (i + step + step) >= count ? count : (i + step + step);
for (k = 0; k < step; k++)
leftArray[k] = frags[a + k];
j1 = 0;
j2 = 0;
for (k = a; k < c; k++)
{
if (b + j1 >= c || (j2 < step && leftArray[j2].depth > frags[b + j1].depth))
frags[k] = leftArray[j2++];
else
frags[k] = frags[b + j1++];
}
////////////////////////////////////////////////////////////////////////
i += 2 * step;
}
step *= 2;
}
vec4 color = vec4(0, 0, 0, 0);
for( int i = 0; i < count; i++)
{
color.rgb = frags[i].color.rgb * frags[i].color.a + color.rgb * (1 - frags[i].color.a);
color.a = frags[i].color.a + color.a * (1 - frags[i].color.a);
}
fcolor = color;
})";
odfaeg::graphic::Shader shader, skyboxShader, perPixelLinkedListP1Shader, perPixelLinkedListP2Shader;
shader.loadFromMemory(cubeMapsVS, cubeMapsFS);
skyboxShader.loadFromMemory(skyboxVS, skyboxFS);
perPixelLinkedListP1Shader.loadFromMemory(skyboxVS, perPixelLinkedListP1FS);
perPixelLinkedListP2Shader.loadFromMemory(perPixelLinkedListP2VS, perPixelLinkedListP2FS);
// set up vertex data (and buffer(s)) and configure vertex attributes
// ------------------------------------------------------------------
float cubeVertices[] = {
// positions // normals
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f,
-0.5f, 0.5f, -0.5f, -1.0f, 0.0f, 0.0f,
-0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f,
-0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f,
-0.5f, -0.5f, 0.5f, -1.0f, 0.0f, 0.0f,
-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f,
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
-0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f,
0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f,
0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f,
0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f,
-0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f,
-0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
-0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f
};
// set up vertex data (and buffer(s)) and configure vertex attributes
// ------------------------------------------------------------------
float skyboxVertices[] = {
// positions
-1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
-1.0f, -1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, -1.0f,
1.0f, -1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, -1.0f, 1.0f,
-1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, -1.0f,
1.0f, 1.0f, -1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, 1.0f
};
float fullScreenQuadVertices[] = {
// positions
-1.0f, 1.0f, 0.0f,
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
1.0f, 1.0f, 0.0f,
-1.0f, 1.0f, 0.0f,
};
// cube VAO
unsigned int cubeVAO, cubeVBO;
glGenVertexArrays(1, &cubeVAO);
glGenBuffers(1, &cubeVBO);
glBindVertexArray(cubeVAO);
glBindBuffer(GL_ARRAY_BUFFER, cubeVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(cubeVertices), &cubeVertices, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)(3 * sizeof(float)));
// skybox VAO
unsigned int skyboxVAO, skyboxVBO;
glGenVertexArrays(1, &skyboxVAO);
glGenBuffers(1, &skyboxVBO);
glBindVertexArray(skyboxVAO);
glBindBuffer(GL_ARRAY_BUFFER, skyboxVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(skyboxVertices), &skyboxVertices, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
// load textures
// -------------
vector<std::string> faces
{
"tilesets/skybox/right.jpg",
"tilesets/skybox/left.jpg",
"tilesets/skybox/top.jpg",
"tilesets/skybox/bottom.jpg",
"tilesets/skybox/front.jpg",
"tilesets/skybox/back.jpg"
};
std::vector<sf::Image> images;
for (unsigned int i = 0; i < 6; i++) {
sf::Image image;
image.loadFromFile(faces[i]);
images.push_back(image);
}
int width = images[0].getSize().x;
int height = images[0].getSize().y;
odfaeg::graphic::Texture cubeMapTex, cubeMapFBOTex;
cubeMapTex.createCubeMap(width, height, images);
cubeMapFBOTex.createCubeMap(SCR_WIDTH, SCR_WIDTH);
glEnable(GL_TEXTURE_CUBE_MAP);
sf::Context context(sf::ContextSettings(0, 0, 4, 4, 6), SCR_WIDTH, SCR_WIDTH);
context.setActive(true);
unsigned int skyboxVAOFBO, fsQuadVAO, fsQuadVBO;
glGenVertexArrays(1, &skyboxVAOFBO);
glBindVertexArray(skyboxVAOFBO);
glBindBuffer(GL_ARRAY_BUFFER, skyboxVBO);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glGenVertexArrays(1, &fsQuadVAO);
glGenBuffers(1, &fsQuadVBO);
glBindVertexArray(fsQuadVAO);
glBindBuffer(GL_ARRAY_BUFFER, fsQuadVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(fullScreenQuadVertices), &fullScreenQuadVertices, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
GLuint frameBufferID;
glGenFramebuffers(1, &frameBufferID);
glBindFramebuffer(GL_FRAMEBUFFER, frameBufferID);
glDrawBuffer(GL_COLOR_ATTACHMENT0);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, cubeMapFBOTex.getNativeHandle(), 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
std::cerr << "Impossible to create render texture (failed to link the target texture to the frame buffer)" << std::endl;
return false;
}
GLuint atomicBuffer, linkedListBuffer, headPtrTex, clearBuf;
GLuint maxNodes = 5 * SCR_WIDTH * SCR_WIDTH;
GLint nodeSize = 5 * sizeof(GLfloat) + sizeof(GLuint);
glGenBuffers(1, &atomicBuffer);
glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, atomicBuffer);
glBufferData(GL_ATOMIC_COUNTER_BUFFER, sizeof(GLuint), nullptr, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, 0);
glGenBuffers(1, &linkedListBuffer);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, linkedListBuffer);
glBufferData(GL_SHADER_STORAGE_BUFFER, maxNodes * nodeSize, NULL, GL_DYNAMIC_DRAW);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
glGenTextures(1, &headPtrTex);
glBindTexture(GL_TEXTURE_2D, headPtrTex);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_R32UI, SCR_WIDTH, SCR_WIDTH);
glBindImageTexture(0, headPtrTex, 0, GL_FALSE, 0, GL_READ_WRITE, GL_R32UI);
glBindTexture(GL_TEXTURE_2D, 0);
std::vector<GLuint> headPtrClearBuf(SCR_WIDTH*SCR_WIDTH, 0xffffffff);
glGenBuffers(1, &clearBuf);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, clearBuf);
glBufferData(GL_PIXEL_UNPACK_BUFFER, headPtrClearBuf.size() * sizeof(GLuint),
&headPtrClearBuf[0], GL_STATIC_COPY);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, atomicBuffer);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, linkedListBuffer);
// shader configuration
// --------------------
shader.setParameter("skybox", cubeMapFBOTex);
skyboxShader.setParameter("skybox", cubeMapTex);
perPixelLinkedListP1Shader.setParameter("maxNodes", maxNodes);
perPixelLinkedListP1Shader.setParameter("skybox", cubeMapTex);
int oldX = sf::Mouse::getPosition(window).x;
int oldY = sf::Mouse::getPosition(window).y;
sf::Clock time;
// run the main loop
bool running = true;
glEnable(GL_TEXTURE_CUBE_MAP);
while (running)
{
// per-frame time logic
// --------------------
// per-frame time logic
// --------------------
float currentFrame = time.getElapsedTime().asSeconds();
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
// handle events
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
// end the program
running = false;
}
else if (event.type == sf::Event::Resized)
{
// adjust the viewport when the window is resized
glViewport(0, 0, event.size.width, event.size.height);
}
else if (event.type == sf::Event::MouseMoved) {
if (firstMouse)
{
lastX = event.mouseMove.x;
lastY = event.mouseMove.y;
firstMouse = false;
}
float xoffset = event.mouseMove.x - lastX;
float yoffset = lastY - event.mouseMove.y; // reversed since y-coordinates go from bottom to top
lastX = event.mouseMove.x;
lastY = event.mouseMove.y;
camera.ProcessMouseMovement(xoffset, yoffset);
} else if (event.type == sf::Event::MouseWheelScrolled) {
camera.ProcessMouseScroll(event.mouseWheelScroll.delta);
}
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
camera.ProcessKeyboard(FORWARD, deltaTime);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
camera.ProcessKeyboard(BACKWARD, deltaTime);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
camera.ProcessKeyboard(RIGHT, deltaTime);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
camera.ProcessKeyboard(LEFT, deltaTime);
}
// clear the buffers
// render
// ------
window.setActive(true);
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
context.setActive(true);
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
for (unsigned int i = 0; i < 6; i++) {
GLuint zero = 0;
glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, atomicBuffer);
glBufferSubData(GL_ATOMIC_COUNTER_BUFFER, 0, sizeof(GLuint), &zero);
glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, 0);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, clearBuf);
glBindTexture(GL_TEXTURE_2D, headPtrTex);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, SCR_WIDTH, SCR_WIDTH, GL_RED_INTEGER,
GL_UNSIGNED_INT, NULL);
glBindTexture(GL_TEXTURE_2D, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, cubeMapFBOTex.getNativeHandle(), 0);
glViewport(0, 0, SCR_WIDTH, SCR_WIDTH);
glm::mat4 view;
if (i == 0) {
view = camera2.lookAt(FORWARD);
}
if (i == 1) {
view = camera2.lookAt(BACKWARD);
}
if (i == 2) {
view = camera2.lookAt(UP);
}
if (i == 3) {
view = camera2.lookAt(DOWN);
}
if (i == 4) {
view = camera2.lookAt(RIGHT);
}
if (i == 5) {
view = camera2.lookAt(LEFT);
}
glm::mat4 projection = glm::perspective(glm::radians(camera2.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
odfaeg::graphic::Shader::bind(&perPixelLinkedListP1Shader);
Matrix4f viewMatrix = glmToODFAEGMatrix(view);
Matrix4f projectionMatrix = glmToODFAEGMatrix(projection);
perPixelLinkedListP1Shader.setParameter("view", viewMatrix);
perPixelLinkedListP1Shader.setParameter("projection", projectionMatrix);
// skybox cube
glBindVertexArray(skyboxVAOFBO);
glActiveTexture(GL_TEXTURE0);
odfaeg::graphic::Texture::bind(&cubeMapTex, odfaeg::graphic::Texture::Normalized);
glDrawArrays(GL_TRIANGLES, 0, 36);
glBindVertexArray(0);
glFinish();
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
odfaeg::graphic::Shader::bind(&perPixelLinkedListP2Shader);
glm::mat4 model = glm::mat4(1.0f);
view = camera2.lookAt(FORWARD);
projection = glm::perspective(glm::radians(camera2.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
Matrix4f modelMatrix = glmToODFAEGMatrix(model);
viewMatrix = glmToODFAEGMatrix(view);
projectionMatrix = glmToODFAEGMatrix(projection);
perPixelLinkedListP2Shader.setParameter("model", modelMatrix);
perPixelLinkedListP2Shader.setParameter("view", viewMatrix);
perPixelLinkedListP2Shader.setParameter("projection", projectionMatrix);
glBindVertexArray(fsQuadVAO);
glActiveTexture(GL_TEXTURE0);
odfaeg::graphic::Texture::bind(nullptr, odfaeg::graphic::Texture::Normalized);
glDrawArrays(GL_TRIANGLES, 0, 6);
glBindVertexArray(0);
glFinish();
}
glMemoryBarrier(GL_ALL_BARRIER_BITS);
glFlush();
window.setActive(true);
glViewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
// draw...
odfaeg::graphic::Shader::bind(&shader);
glm::mat4 model = glm::mat4(1.0f);
glm::mat4 view = camera.GetViewMatrix();
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
Matrix4f modelMatrix = glmToODFAEGMatrix(model);
Matrix4f viewMatrix = glmToODFAEGMatrix(view);
Matrix4f projectionMatrix = glmToODFAEGMatrix(projection);
shader.setParameter("model", modelMatrix);
shader.setParameter("view", viewMatrix);
shader.setParameter("projection", projectionMatrix);
shader.setParameter("cameraPos", camera.Position.x,camera.Position.y,camera.Position.z);
// cubes
glBindVertexArray(cubeVAO);
glActiveTexture(GL_TEXTURE0);
odfaeg::graphic::Texture::bind(&cubeMapFBOTex, odfaeg::graphic::Texture::Normalized);
glDrawArrays(GL_TRIANGLES, 0, 36);
glBindVertexArray(0);
// draw skybox as last
glDepthFunc(GL_LEQUAL); // change depth function so depth test passes when values are equal to depth buffer's content
odfaeg::graphic::Shader::bind(&skyboxShader);
view = glm::mat4(glm::mat3(camera.GetViewMatrix())); // remove translation from the view matrix
viewMatrix = glmToODFAEGMatrix(view);
skyboxShader.setParameter("view", viewMatrix);
skyboxShader.setParameter("projection", projectionMatrix);
// skybox cube
glBindVertexArray(skyboxVAO);
glActiveTexture(GL_TEXTURE0);
odfaeg::graphic::Texture::bind(&cubeMapTex, odfaeg::graphic::Texture::Normalized);
glDrawArrays(GL_TRIANGLES, 0, 36);
glBindVertexArray(0);
glDepthFunc(GL_LESS); // set depth function back to default
// end the current frame (internally swaps the front and back buffers)
window.display();
oldX = sf::Mouse::getPosition(window).x;
oldY = sf::Mouse::getPosition(window).y;
}
// optional: de-allocate all resources once they've outlived their purpose:
// ------------------------------------------------------------------------
glDeleteVertexArrays(1, &cubeVAO);
glDeleteVertexArrays(1, &skyboxVAO);
glDeleteVertexArrays(1, &skyboxVAOFBO);
glDeleteBuffers(1, &cubeVBO);
glDeleteBuffers(1, &skyboxVAO);
// release resources...
return 0;
}
Matrix4f glmToODFAEGMatrix(glm::mat4 mat) {
Matrix4f odfaegMatrix(mat[0][0], mat[0][1], mat[0][2], mat[0][3],
mat[1][0], mat[1][1], mat[1][2], mat[1][3],
mat[2][0], mat[2][1], mat[2][2], mat[2][3],
mat[3][0], mat[3][1], mat[3][2], mat[3][3]);
return odfaegMatrix;
}
What’s the matter ?
Thanks
Ok I’ve found the problem, SOLVED.