Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Resize window of app with native OpenGL render  (Read 2064 times)

0 Members and 1 Guest are viewing this topic.

Meteorhead

  • Newbie
  • *
  • Posts: 22
    • View Profile
Resize window of app with native OpenGL render
« on: May 11, 2012, 11:52:55 am »
Hi,

I have read through the search hits to this problem and found no solution, so I take the liberty of posting a new question after roughly an hour of debug to no avail.

I have an app that uses native rendering beside SFML text render, and I have a problem when I resize my window. Infact the entire screen turns black.

Every frame when I render my things, I issue glUseProgam() to enable using my shaders, and when redering text, I use push/popGLStates to save my state of the statemachine, and to revert it back. I have found that push states does not save the program being used, that's why I lazily issue it every time before render. However, when I handle events at the begininng of the guiLoop(), I have to update my viewMatrix inside the shader. For that I need glUseProgram so the application knows which shader should have it's matrix updated. Here is the code:

// Set view matrix upon window resize
if (event.type == sf::Event::Resized)
{
        m_matProj = glm::perspective( 45.0f, ((float)event.size.width)/event.size.height, 0.01f, 100.0f);
        OpenGL.lock();
        mainWindow->setActive();
        mainWindow->setView(sf::View(sf::FloatRect(0, 0, (float)event.size.width, (float)event.size.height)));
        glViewport(0, 0, event.size.width, event.size.height); auxRuntime->checkErr(glGetError(), cl::ERR, "glViewPort()");
//      glUseProgram(glProgram); auxRuntime->checkErr(glGetError(), cl::ERR, "glUseProgram(glProgram)");
        std::cout << glProgram << "  " << projectionMatrixLocation << "\n";
        glUniformMatrix4fv(projectionMatrixLocation, 1, GL_FALSE, &m_matProj[0][0]);
        auxRuntime->checkErr(glGetError(), cl::ERR, "glUniformMatrix4fv(projectionMatrix)");
        mainWindow->setActive(false);
        OpenGL.unlock();
}

Funny thing is, having glUseProgram uncommented, things only distort, but when I actually try to update the matrix, the screen turns black. It is the very same routine I used to initialize the matrix in the first place.

What am I doing wrong?
« Last Edit: May 11, 2012, 11:58:01 am by Laurent »

Meteorhead

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Resize window of app with native OpenGL render
« Reply #1 on: May 11, 2012, 12:01:57 pm »
Forgive me, but 2 minutes after posting (yes, 62 minutes of debugging) I found the problem. The statement (exactly the same routine) made me think, and infact they were not the same, and the far culling distance was too small.

Anyhow... I'll be off to finding the second bug in my app (2 days of debugging this last issue actually, but I'll give it a little more thought).

I'll leave the code sniplet here in case someone would actually really mess up a resize routine, cause this one works ( you might want to remove the debug instructions though).
« Last Edit: May 11, 2012, 12:03:33 pm by Meteorhead »

 

anything