Sign in to follow this  

SDL_WINDOWEVENT_EXPOSED not occurring

This topic is 1113 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

I am following this guide: http://davidgow.net/handmadepenguin/ch2.html

 

I am trying to get the screen to flip between black and white when it is redrawn.  According to this guide, it is saying for now to put the render code when the SDL_WINDOWEVENT_EXPOSED event occurs.  However, this event never seems to occur (confirmed through LLDB).  According to the SDL documentation, it seems that the event occurs when part of the window is covered by another window.  I have tried doing this to no avail.  The window stays black at all times.

 

I can't seem to find anything on Google.

 

The difference between me and this guide is that I am doing this on OS X.  Could this be the reason?

 

Here is my code:

 

void render(SDL_Window* window) {
    SDL_Renderer* renderer = SDL_GetRenderer(window);


    static bool isBlack = true;


    if (isBlack) {
        SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
        isBlack = false;
    }
    else {
        SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
        isBlack = true;
    }


    SDL_RenderClear(renderer);
    SDL_RenderPresent(renderer);
}


void processWindowEvent(SDL_WindowEvent* we){
    switch (we->event) {
        case SDL_WINDOWEVENT_RESIZED: //this occurs at the proper time (when the window is resized)
            printf("SDL_WINDOWEVENT_RESIZED (%d, %d)\n", we->data1, we->data2);
            break;
        case SDL_WINDOWEVENT_EXPOSED: //this is never hit
            render(SDL_GetWindowFromID(we->windowID));
            break;        
    }
}


void processEvent(SDL_Event* e) {
    switch (e->type) {
        case SDL_QUIT:
            running = false;
            break;
        case SDL_WINDOWEVENT:
            processWindowEvent(&e->window);
            break;
    }
}

Thanks very much!

 

Share this post


Link to post
Share on other sites
SDL_WINDOWEVENT_EXPOSED is just for when the graphics has to be redrawn. I'm not sure exactly when this happens but it probably depends on a lot of things. If the renderer is not hardware accelerated I suspect you never get this event.

If you want the graphics to update you should call the render function from somewhere else in the code. If you always update the whole screen very often you can probably ignore SDL_WINDOWEVENT_EXPOSED.

Share this post


Link to post
Share on other sites

Okay cool.  Odd that the guide was telling to do this (and it is not hardware accelerated in the guide).  Maybe it sends this event on Linux (which is what he was using).   

 

Thanks!

Share this post


Link to post
Share on other sites

Okay cool.  Odd that the guide was telling to do this (and it is not hardware accelerated in the guide).  Maybe it sends this event on Linux (which is what he was using).   
 
Thanks!

Assuming you're making a game you'll usually just be running things in a loop and drawing as often as you can, redrawing the entire screen. Reactive events like those are usually designed for standard desktop apps, where things will rarely if ever change onscreen and only need to be redrawn periodically. You won't have any timing control over reactive events, so if you need time at all you'll have to use a loop.

Usually you'd want something like this for your basic loop.
bool running = true;

while(running)
{
    SDL_Event Event;
    while(SDL_PollEvent(&Event))
    {
       // Do stuff here..
    }

    // Update

    // Draw
}

Share this post


Link to post
Share on other sites

This topic is 1113 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this