Gamma SDL

Simple Directmedia Layer: Portable Spieleprogrammierung
Antworten
hardcoding
Beiträge: 91
Registriert: Do Okt 04, 2012 9:24 pm

Gamma SDL

Beitrag von hardcoding » Sa Mai 04, 2013 12:18 pm

hallo,

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);
}
In diesem Codeschnipsel :

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));
		}
	}
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

Code: Alles auswählen

FillRect.w=1;
FillRect.h=1;
FillRect.Y=SCREEN_HEIGHT;
FillRect.X=SCREEN_WIDTH;
Hat man bei der Konsole nicht das gleiche Ergebnis wie mit einer For Schleife. Wie lässt sich das erklären ?

Benutzeravatar
cloidnerux
Moderator
Beiträge: 3123
Registriert: Fr Sep 26, 2008 4:37 pm
Wohnort: Ram (Gibts wirklich)

Re: Gamma SDL

Beitrag von cloidnerux » Sa Mai 04, 2013 3:17 pm

Wrsl weil in den for-schleifen das Rechteck nicht außerhalb des Bildschirmbereiches geschoben wird.
Wenn du die X- und Y-Koordinate auf die Bildschirmhöhe und Breite in Pixeln setzt, bei einem bei 0 beginnenden System, liegt der Punkt (SCREEN_WIDTH|SCREEN_HEIGHT) außerhalb des Bildschirmbereiches.

Dann aber noch mal die obligatorische Frage: Was ist dien Problem? Was erwartest du, was erhälst du stattdessen?
Redundanz macht wiederholen unnötig.
quod erat expectandum

hardcoding
Beiträge: 91
Registriert: Do Okt 04, 2012 9:24 pm

Re: Gamma SDL

Beitrag von hardcoding » Sa Mai 04, 2013 10:05 pm

Wenn du die X- und Y-Koordinate auf die Bildschirmhöhe und Breite in Pixeln setzt, bei einem bei 0 beginnenden System, liegt der Punkt (SCREEN_WIDTH|SCREEN_HEIGHT) außerhalb des Bildschirmbereiches.
Naja ich habe es mit anderen Werten innerhalb der Surface versucht ,trotzdessen das gleiche Ergebnis.

Code: Alles auswählen

Dann aber noch mal die obligatorische Frage: Was ist dien Problem? Was erwartest du, was erhälst du stattdessen?
Wie meinst du das?



PS:Hat sich erledigt.

Benutzeravatar
cloidnerux
Moderator
Beiträge: 3123
Registriert: Fr Sep 26, 2008 4:37 pm
Wohnort: Ram (Gibts wirklich)

Re: Gamma SDL

Beitrag von cloidnerux » So Mai 05, 2013 1:06 am

Wie meinst du das?



PS:Hat sich erledigt.
Du hast einen Code übernommen und hast dabei eine bestimmte Ausgabe erwartet, aber eine andere bekommen. Die Frage die ich stelle ist nun diese, welche Ausgabe/Ergebnis du erwartest und welches du bekommst.

Und wie hast du nun dein Problem gelöst?
Redundanz macht wiederholen unnötig.
quod erat expectandum

Antworten