Skip to main content
GameDev.net gamedev.net
🔒 Locked

SDL_UpdateRects

Started by Gaiiden Oct 30, 2002 at 10:01 PM 0 replies 900+ views
Original Post
Gaiiden
Gaiiden
This is rather weird. I have a closed-loop input function (the rest of the app freezes until input is done) that updates the input area only via a call to SDL_UpdateRects(). The only problem is that in a fullscreen app this doesn't seem to work at all. The function takes a surface to draw to and update, and I pass in the primary surface. I have a feeling the windowed mode handle page flipping differently than the fullscreen mode or something because when I try flipping the page in fullscreen I get two different surfaces flickering in and out, but that doesn't happen in windowed mode. I'm pretty confused right now and I'm still sifting through the possibilities. Just wondering if anyone else has run up against the same problem. Here's the code for the input function, dunno if it'll do any good tho. It wasn't written by me so don't whine to me about how it looks
    
string SoFont::InputText(SDL_Surface *Dest, int x, int y, const char *input, int clip_w, int clip_h)
{
    string str_input;
    SDL_Event event;
    int ch=-1,blink=0;
    long blinktimer=0;
    SDL_Surface *Back;
    SDL_Rect rect;
    int previous;
    //int ofs=(text[0]-33)*2+1;

    //int leftshift=(this->CharPos[ofs]-this->CharPos[ofs-1])/2;

    
    Back = SDL_AllocSurface(Dest->flags,				                    Dest->w,
    			    FontHeight(),
    			    Dest->format->BitsPerPixel,
    			    Dest->format->Rmask,
    			    Dest->format->Gmask,
			    Dest->format->Bmask, 0);
    rect.x=0;
    rect.y=y;
    rect.w=Dest->w;
    rect.h=picture->h;
    SDL_BlitSurface(Dest, ▭, Back, NULL);
    PutString(Dest,x,y,input);
    SDL_UpdateRects(Dest, 1, ▭);
        
    // start input

    str_input.assign(input);
    previous=SDL_EnableUNICODE(1);
    SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
    blinktimer=SDL_GetTicks();
    while (ch!=SDLK_RETURN) {
	if (event.type==SDL_KEYDOWN) {
	    ch=event.key.keysym.unicode;
		if (event.key.keysym.sym==SDLK_DELETE)
			str_input = "";
	    if (((ch>31)||(ch=='\b')) && (ch<128)) {
		if ((ch=='\b')&&(str_input.size()>0))
		    str_input.replace(str_input.size()-1, 1, "");
		else if (ch!='\b')
		    str_input += ch;
		SDL_BlitSurface( Back, NULL, Dest, ▭);
		PutString(Dest, x, y, str_input.c_str());
		SDL_UpdateRects(Dest, 1, ▭);
//		printf("%s ## %d\n",text,strlen(text));

		SDL_WaitEvent(&event);
	    }
	}
	if (SDL_GetTicks()>blinktimer) {
	    blink=1-blink;
	    blinktimer=SDL_GetTicks()+500;
	    if (blink) {
		PutString(Dest, x+TextWidth(str_input.c_str()), y, "|");
		SDL_UpdateRects(Dest, 1, ▭);
//		SDL_UpdateRect(Dest, x+TextWidth2(Font,text), y, TextWidth2(Font,"|"), Font->Surface->h);

	    } else {
		SDL_BlitSurface( Back, NULL, Dest, ▭);
		if (!PutString(Dest, x, y, str_input.c_str()), clip_w, clip_h, false)
			str_input.replace(str_input.size()-1, 1, "");
		SDL_UpdateRects(Dest, 1, ▭);
//		SDL_UpdateRect(Dest, x-(Font->CharPos[ofs]-Font->CharPos[ofs-1])/2, y, PixelWidth, Font->Surface->h);

	    }
	}
	SDL_Delay(1);
	SDL_PollEvent(&event);
    }
    str_input += '\0';
    SDL_FreeSurface(Back);
    SDL_EnableUNICODE(previous);  //restore the previous state

    SDL_EnableKeyRepeat(0, 0);

    return str_input;
}
    
_________________________________________________________________ Drew Sikora A.K.A. Gaiiden ICQ #: 70449988 AOLIM: DarkPylat Blade Edge Software Staff Member, GDNet Public Relations, Game Institute 3-time Contributing author, Game Design Methods , Charles River Media Online column - Design Corner at Pixelate Unnoficial IGDA chat! [polaris.starchat.net -> #igda] NJ IGDA Chapter - NJ developers unite!! [Chapter Home | Chapter Forum] "Real programmers don't work from 9 to 5. If any real programmers are around at 9am it's because they were up all night." -Anon. "It's not the size of the source that matters, it's how you use it" - Self
Drew Sikora
Executive Producer
GameDev.net
Gaiiden
Gaiiden
Good no one's replied yet, cause I figured it out.

The main problem was my misconception that windowed apps were double buffered. Even though I tried creating a double buffered windowed app via SDL_RESIZABLE | SDL_DOUBLEBUF | SDL_HWSURFACE flags thrown together, it doesn't work. It's just I kept thinking that way since I use the SDL_Flip() function. However reading the docs again I see that if there is only one surface, SDL_Flip() automatically uses SDL_UpdateRect() instead. doh.

So the reason SDL_UpdateRects isn't working right in the fullscreen app is... well, it is working correctly - it's just that I'm not updating the rest of the surface so when the page flips, only the text input area remains static and the rest of the screen that has differences between the two pages flickers as the two pages switch back and forth.

So I've passed in the function that I use to render the entire screen as a function pointer and the input function calls that to flip the screen so now the fullscreen input works... to a degree. Now that I've successfully redrawn the screen and removed the flickering - the input text no longer shows cause the render function doesn't redraw it!

oh the sweet irony of it all - lol. I guess I didn't integrate the SoFont lib into my framework as well as I thought i did The text should update automatically. Oh well we can fix that...
Drew Sikora
Executive Producer
GameDev.net

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.