Browse Source

working inverted z

testing
totallyfake 1 year ago
parent
commit
61af2d87db
4 changed files with 18 additions and 12 deletions
  1. 7
    3
      src/game.cpp
  2. 5
    7
      src/graphics/skybox.cpp
  3. 3
    2
      src/scenes/testscene.cpp
  4. 3
    0
      src/window.cpp

+ 7
- 3
src/game.cpp View File

@@ -68,6 +68,7 @@ void Game::init() {
glClearDepth(0.0f);
glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE);

/*
//depth buffer stuff
glGenTextures(1, &mColor);
glBindTexture(GL_TEXTURE_2D, mColor);
@@ -88,6 +89,7 @@ void Game::init() {
fprintf(stderr, "glCheckFramebufferStatus: %x\n", status);
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
*/

running = false;
gls::setTracking(true); // track OpenGL state changes
@@ -114,15 +116,16 @@ void Game::loop() {
activeScene->update(dTime);

glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
//glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
glDepthFunc(GL_GREATER);
glClearDepth(0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
activeScene->draw(); //draw the scene
glBindFramebuffer(GL_FRAMEBUFFER, 0);
//glBindFramebuffer(GL_FRAMEBUFFER, 0);

/*
glBindFramebuffer(GL_READ_FRAMEBUFFER, mFBO);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); // default FBO
glBlitFramebuffer(
@@ -130,6 +133,7 @@ void Game::loop() {
0, 0, conf->getValue<int>("graphics.res.x", 800), conf->getValue<int>("graphics.res.y", 600),
GL_COLOR_BUFFER_BIT, GL_LINEAR);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
*/

SDL_GL_SwapWindow(window.getWindow());
}

+ 5
- 7
src/graphics/skybox.cpp View File

@@ -79,19 +79,17 @@ namespace vtk {

void Skybox::draw(RenderTask& task) {
auto camera = task.getCamera();
camera.getViewMatrix();
auto viewMat = camera.getAngleMatrix();
auto pos = camera.getPosition();
auto proj = camera.getProjectionMatrix();
gls::setShader(mShader);
glUseProgram(mShader);
glUniformMatrix4fv(mViewMat, 1, GL_FALSE, glm::value_ptr(viewMat));
glUniformMatrix4fv(mProjMat, 1, GL_FALSE, glm::value_ptr(proj));
gls::setFlag(GL_DEPTH_TEST, false);
glDisable(GL_DEPTH_TEST);
glBindVertexArray(mVao);
glDrawArrays(GL_TRIANGLES, 0, 36);
gls::restoreState();
glEnable(GL_DEPTH_TEST);
}

}

+ 3
- 2
src/scenes/testscene.cpp View File

@@ -62,7 +62,7 @@ void TestScene::init() {
mSkyboxTask = new RenderTask(mSkybox, camera, linkedGame->window);

glUniformMatrix4fv(viewMatUni, 1, GL_FALSE, glm::value_ptr(camera.getViewMatrix()));
glUniformMatrix4fv(projMatUni, 1, GL_FALSE, glm::value_ptr(linkedGame->window.getProjectionMatrix()));
glUniformMatrix4fv(projMatUni, 1, GL_FALSE, glm::value_ptr(camera.getProjectionMatrix()));

//nanovg
vg = nvgCreateGL3(NVG_ANTIALIAS | NVG_STENCIL_STROKES);
@@ -203,8 +203,9 @@ void TestScene::draw() {
mSkyboxTask->draw();

//draw world TODO: move this to rendertasks
gls::setShader(shaders);
glUseProgram(shaders);
glUniformMatrix4fv(viewMatUni, 1, GL_FALSE, glm::value_ptr(camera.getViewMatrix()));
glUniformMatrix4fv(projMatUni, 1, GL_FALSE, glm::value_ptr(camera.getProjectionMatrix()));
world.draw();

glDisable(GL_DEPTH_TEST);

+ 3
- 0
src/window.cpp View File

@@ -32,7 +32,10 @@ bool Window::create() {
window = SDL_CreateWindow(title.c_str(),
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
mWidth, mHeight, SDL_WINDOW_OPENGL);
context = SDL_GL_CreateContext(window);

SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32);
return true;

}

Loading…
Cancel
Save