Gamma SDL
Verfasst: Sa Mai 04, 2013 12:18 pm
hallo,
Ich bins wieder mit einer neuen Frage und zwar:
In diesem Codeschnipsel :
wird die Surface mit zufälligen Farben gefüllt. Dabei inkrementiert er Y und X sodass die größe des Rechteck verändert wird.
Schön und gut. Meine Frage lautet nun: Wenn ich die Y und X Punkte gleich hohe Werte verpasse ohne die For schleife zu benutzen wie hier
Hat man bei der Konsole nicht das gleiche Ergebnis wie mit einer For Schleife. Wie lässt sich das erklären ?
Ich bins wieder mit einer neuen Frage und zwar:
Code: Alles auswählen
#include "SDL/SDL.h"
//include ability to exit program
#include <stdlib.h>
//screen dimensions
const int SCREEN_WIDTH=640;
const int SCREEN_HEIGHT=480;
//display surface
SDL_Surface* g_pDisplaySurface = NULL;
//event structure
SDL_Event g_Event;
//gamma values
float g_RedGamma=1.0f;
float g_GreenGamma=1.0f;
float g_BlueGamma=1.0f;
//change in gamma value from one frame to the next
float g_GammaDelta=-0.01f;
//main function
int main(int argc, char* argv[])
{
//initialize SDL
if (SDL_Init(SDL_INIT_VIDEO)==-1)
{
//error initializing SDL
//report the error
fprintf(stderr,"Could not initialize SDL!\n");
//end the program
exit(1);
}
else
{
//SDL initialized
//report success
fprintf(stdout,"SDL initialized properly!\n");
//set up to uninitialize SDL at exit
atexit(SDL_Quit);
}
//create windowed environment
g_pDisplaySurface = SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,16,SDL_FULLSCREEN);
//error check
if (g_pDisplaySurface == NULL)
{
//report error
fprintf(stderr,"Could not set up display surface!\n");
//exit the program
exit(1);
}
//fill surface with random pixel data using color fills
SDL_Rect FillRect;
FillRect.w=1;
FillRect.h=1;
for(FillRect.y=0;FillRect.y<SCREEN_HEIGHT;FillRect.y++)
{
for(FillRect.x=0;FillRect.x<SCREEN_WIDTH;FillRect.x++)
{
SDL_FillRect(g_pDisplaySurface,&FillRect,SDL_MapRGB(g_pDisplaySurface->format,rand()%256,rand()%256,rand()%256));
}
}
//set initial gamma values
if(SDL_SetGamma(g_RedGamma,g_GreenGamma,g_BlueGamma)==-1)
{
fprintf(stdout,"Gamma not supported.\n");
fprintf(stdout,"%s\n",SDL_GetError());
exit(1);
}
//repeat forever
for(;;)
{
//wait for an event
if(SDL_PollEvent(&g_Event)==0)
{
//change the gamma values
g_RedGamma+=g_GammaDelta;
g_GreenGamma+=g_GammaDelta;
g_BlueGamma+=g_GammaDelta;
//check for 0.0 or 1.0
if(g_RedGamma<=0.0f||g_RedGamma>=1.0f) g_GammaDelta=-g_GammaDelta;
//set new gamma
SDL_SetGamma(g_RedGamma,g_GreenGamma,g_BlueGamma);
//update the screen
SDL_UpdateRect(g_pDisplaySurface,0,0,0,0);
}
else
{
//event occurred, check for quit
if(g_Event.type==SDL_QUIT) break;
//if a key was pressed, quit
if(g_Event.type==SDL_KEYDOWN) break;
}
}
//normal termination
fprintf(stdout,"Terminating normally.\n");
//return 0
return(0);
}
Code: Alles auswählen
for(FillRect.y=0;FillRect.y<SCREEN_HEIGHT;FillRect.y++)
{
for(FillRect.x=0;FillRect.x<SCREEN_WIDTH;FillRect.x++)
{
SDL_FillRect(g_pDisplaySurface,&FillRect,SDL_MapRGB(g_pDisplaySurface->format,rand()%256,rand()%256,rand()%256));
}
}
Schön und gut. Meine Frage lautet nun: Wenn ich die Y und X Punkte gleich hohe Werte verpasse ohne die For schleife zu benutzen wie hier
Code: Alles auswählen
FillRect.w=1;
FillRect.h=1;
FillRect.Y=SCREEN_HEIGHT;
FillRect.X=SCREEN_WIDTH;