Jump to content
  • Advertisement
Sign in to follow this  
3dmodelerguy

no refresh weird problem please help

This topic is 4971 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

my code:
#include "PrecompiledHeaders.h"
#include "MainApp.h"
#include "GameWindow.h"
#include "GLCanvas.h"

int Default_Window_Value = -1;

DWORD Default_GL_Style = wxNO_BORDER;

wxString Empty_String;

IMPLEMENT_APP( MainApp );

bool MainApp::OnInit()
{

        int Default_Window_Value = -1;
        DWORD Default_GL_Style = wxNO_BORDER;
        wxString Empty_String;
       
        MainGameWindow *GameWindow = new MainGameWindow( _T ( "Stromgage Game Engine" ), wxPoint( 100, 100 ), wxSize( 800, 600 ) );

        GLCanvas *MainGLWindow = new GLCanvas( GameWindow, Default_Window_Value, wxPoint( 0, 0 ), wxSize( 800, 600 ), Default_GL_Style, Empty_String );

        GameWindow -> Show( true );

        MainGLWindow -> SetCurrent();

        glClearColor(0.0, 0.0, 0.0, 0.0);
        glColor3f(1.0, 1.0, 1.0);

        glBegin(GL_TRIANGLES);
                glColor3f(.16f, .20f, .36f);
                glVertex3f( -0.5f, -0.5f, 1.0f);
                glColor3f(.54f, .91f, .82f);
                glVertex3f(-0.5, 0.5, 1.0f);
                glColor3f(.13f, .67f, .26f);
                glVertex3f(0.5, 0.5, 1.0f);

        glEnd();
        glFlush();

        MainGLWindow -> SwapBuffers();

        return true;
       
} 

now that compiles fine and runs but if i min the screen and then come back to screen it is blank, just a tanish colour. why does this happen? and how can i fix it.

Share this post


Link to post
Share on other sites
Advertisement
You need to either catch the paint messages in your message loop and redraw your window, or (if you're using GLUT) then set a display callback using glutDisplayFunc().

Share this post


Link to post
Share on other sites
I'd assume that you don't redraw the screen after it is resized. You just render your triangle once to the screen (durring Init) but you also have to keep rendering it afterwards


void MainApp::Run()
{
// Draw triangle
glClearColor(0.0, 0.0, 0.0, 0.0);
glColor3f(1.0, 1.0, 1.0);

glBegin(GL_TRIANGLES);
glColor3f(.16f, .20f, .36f);
glVertex3f( -0.5f, -0.5f, 1.0f);
glColor3f(.54f, .91f, .82f);
glVertex3f(-0.5, 0.5, 1.0f);
glColor3f(.13f, .67f, .26f);
glVertex3f(0.5, 0.5, 1.0f);
glEnd();

m_MainWindow->SwapBuffers();
}

// somewhere else in your code where the message loop is

...
while(appIsRunning)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if(msg.message == WM_QUIT)
appIsRunning = FALSE;

TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
// Call MainApp::Run()
Run();
}

}


Also your init function is (maybe) leaking memory:
GameWindow and MainGLWindow don't get deleted and you don't save the pointers anywhere to get deleted later (at least that's the case in the code snippet you posted).

Regards Martin

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!