|
Trouver une ressource
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
SCREENSAVER HYPNOTISEUR
Information sur la source
Description
Bonjour Un screensaver en SDL pas du tout assez optimisé, je m'en excuse mais sur un pentium 4 il tournera quand même ^^ disons qu'il économise pas beaucoup le processeur le but du jeu c'est de tenir le plus longtemps possible devant, et/ou trouver comment il fonctionne
Source
- #define WW 800
- #define HH 600
- #include <stdio.h>
- #include <stdlib.h>
- #include <SDL/SDL.h>
- #include <math.h>
-
- static SDL_Surface * init(int w, int h, int bpp);
- static void loop(SDL_Surface * s);
- static void manageEvents(SDL_Surface * s);
- static void draw(SDL_Surface * s);
- static void SDL_Rotate(SDL_Surface *src,SDL_Surface *dst, double rotation, int x, int y);
-
-
- int main(int argc, char ** argv) {
- SDL_Surface * s;
- s = init(WW, HH, 32);
- loop(s);
- return 0;
- }
-
- static SDL_Surface * init(int w, int h, int bpp) {
- SDL_Surface * s;
- if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
- exit(1);
- }
- if ( (s = SDL_SetVideoMode(w, h, bpp, SDL_SWSURFACE | SDL_HWSURFACE |SDL_FULLSCREEN )) == NULL ) {
- exit(1);
- }
- int i; Uint32 *t = s->pixels; for (i=0; i < WW*HH; i++) t[i] = 0xFFFFFFFF;
- atexit(SDL_Quit);
- return s;
- }
-
-
- static void loop(SDL_Surface * s) {
- SDL_Surface *s2 = SDL_CreateRGBSurface(SDL_HWSURFACE, WW*2, HH*2, 32, 0, 0, 0, 0);
- static int i,j;
- Uint32 *t = s2->pixels;
- static int count = 0;
- static int yesorno = 0;
- static double rotation3 = M_PI/2000;
- static SDL_Event event;
- static double rotation2 = 2.1543;
- for (i=0; i < WW*2; i++) for (j=0; j < HH*2; j++) t[j*WW+i] = 0;
- for(;;) {
- if (yesorno) rotation3 /= 1.3;
- else rotation3 *= 1.2;
- if (rotation3 < M_PI/500000) { yesorno = !yesorno; rotation3 = M_PI/500000; }
- if (rotation3 > M_PI/1000) { yesorno = !yesorno; rotation3 = M_PI/1000; }
- rotation2 += rotation3;
- while (rotation2 >= 2*M_PI) rotation2 -= 2*M_PI;
- SDL_Rotate(s2,s,rotation2,WW,HH);
- SDL_UpdateRect(s, 0, 0, WW, HH);
- SDL_Delay(1);
- if(SDL_PollEvent(&event) && event.type == SDL_KEYDOWN) exit(0);
- }
- }
-
- static void SDL_Rotate(SDL_Surface *src,SDL_Surface *dst, double rotation, int x, int y) {
- Uint32 *t1 = src->pixels, *t2 = dst->pixels;
- static int i,j,i2,j2,i3,j3;
- static double vi, vj;
- vi = cos(rotation); vj = sin(rotation);
- for (i=0; i < WW*HH; i++) t2[i] = 0xFFFFFFFF;
- for (i=0; i < WW*2; i++)
- for (j=0; j < HH*2; j++) {
- i3 = i - x; j3 = j - y;
- i2 = (double)i3*vi - (double)j3*vj + x - WW/2; j2 = (double)i3*vj + (double)j3*vi + y - HH/2;
- if (i2 >=0 && j2 >= 0 && i2 < WW && j2 < HH)
- t2[j2 * WW + i2] = t1[j * WW + i];
- }
- }
#define WW 800
#define HH 600
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <math.h>
static SDL_Surface * init(int w, int h, int bpp);
static void loop(SDL_Surface * s);
static void manageEvents(SDL_Surface * s);
static void draw(SDL_Surface * s);
static void SDL_Rotate(SDL_Surface *src,SDL_Surface *dst, double rotation, int x, int y);
int main(int argc, char ** argv) {
SDL_Surface * s;
s = init(WW, HH, 32);
loop(s);
return 0;
}
static SDL_Surface * init(int w, int h, int bpp) {
SDL_Surface * s;
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
exit(1);
}
if ( (s = SDL_SetVideoMode(w, h, bpp, SDL_SWSURFACE | SDL_HWSURFACE |SDL_FULLSCREEN )) == NULL ) {
exit(1);
}
int i; Uint32 *t = s->pixels; for (i=0; i < WW*HH; i++) t[i] = 0xFFFFFFFF;
atexit(SDL_Quit);
return s;
}
static void loop(SDL_Surface * s) {
SDL_Surface *s2 = SDL_CreateRGBSurface(SDL_HWSURFACE, WW*2, HH*2, 32, 0, 0, 0, 0);
static int i,j;
Uint32 *t = s2->pixels;
static int count = 0;
static int yesorno = 0;
static double rotation3 = M_PI/2000;
static SDL_Event event;
static double rotation2 = 2.1543;
for (i=0; i < WW*2; i++) for (j=0; j < HH*2; j++) t[j*WW+i] = 0;
for(;;) {
if (yesorno) rotation3 /= 1.3;
else rotation3 *= 1.2;
if (rotation3 < M_PI/500000) { yesorno = !yesorno; rotation3 = M_PI/500000; }
if (rotation3 > M_PI/1000) { yesorno = !yesorno; rotation3 = M_PI/1000; }
rotation2 += rotation3;
while (rotation2 >= 2*M_PI) rotation2 -= 2*M_PI;
SDL_Rotate(s2,s,rotation2,WW,HH);
SDL_UpdateRect(s, 0, 0, WW, HH);
SDL_Delay(1);
if(SDL_PollEvent(&event) && event.type == SDL_KEYDOWN) exit(0);
}
}
static void SDL_Rotate(SDL_Surface *src,SDL_Surface *dst, double rotation, int x, int y) {
Uint32 *t1 = src->pixels, *t2 = dst->pixels;
static int i,j,i2,j2,i3,j3;
static double vi, vj;
vi = cos(rotation); vj = sin(rotation);
for (i=0; i < WW*HH; i++) t2[i] = 0xFFFFFFFF;
for (i=0; i < WW*2; i++)
for (j=0; j < HH*2; j++) {
i3 = i - x; j3 = j - y;
i2 = (double)i3*vi - (double)j3*vj + x - WW/2; j2 = (double)i3*vj + (double)j3*vi + y - HH/2;
if (i2 >=0 && j2 >= 0 && i2 < WW && j2 < HH)
t2[j2 * WW + i2] = t1[j * WW + i];
}
}
Fichier Zip
Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
Télécharger le zip
Sources du même auteur
Sources de la même categorie
Sources en rapport avec celle ci
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
SDL : comment rafraichir l'ecran? [ par smilandfly ]
Bonsoir'je viens de mettre sous sdl (que je viens de decouvrir) mon awale programmé en C++ en mode texte.J'ai 2 problemes qui ne sont sans doute pas t
[SDL] Defilement de l'ecran [ par hoxid ]
Ben voila je voulais savoir comment faire defiler l'ecran, avec SDL.J'y arrive, mais quand le perso arrive au milieu, il bloque. De plus, quand il va
economiseur d'ecran [ par philippexxx ]
philippeje souhaite savoir la difference entre un programme graphique simple en visual c++ et un economiseur d'ecranoucomment transformer un programme
probleme vitesse scrolling [ par gusdark ]
bonjour , j'ai lu pas mal de topics sur le scrolling dans le forum, ce qui m'a permis de comprendre le principe.Mais j'ai cependant un problème que je
SDL [ par lushkah ]
bjr, j'ai un pb avec la SDL en C, je débutes et j'ai passer la nuit a essayer de faire une disparition en fondu, j'essayes de programmer un jeu de da
Message d'erreur avec SL [ par Maximi ]
Bonjour je débute avec C++ et SDL, je travaille avec VC++ 6.J'ai fait un tout petit programme et mon problème, est le suivant :je compile le code et c
aide moi dans la SDL [ par iliassh ]
je veux vos aide pour cree mon jeux en SDL,et je suis trop charger pourque je le rend avant la fin du mois courantje vai l'aide de qq de votre part po
programmation lecteur mp3 [ par dr971 ]
Bonjour,je souhaite realiser un lecteur mp3 en c grace à la librairie fmod mais j'ai un probleme. En fait je souhaite qu'en appuyant sur la touche p d
Probleme en prog SDL.h [ par sieuzac ]
Salut a tous.Je voudrez savoir pourquoi mon va plus vite au TEMP 2 qu'au TEMP 1#include <SDL/SDL.h>#include <stdio.h>#include <time.h&g
|
Téléchargements
Logiciels à télécharger sur le même thème :
Comparez les prix Nouvelle version
|