This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1,50 @@
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <SDL/SDL.h>
unsigned int frames = 0;
unsigned int t_acc = 0;
void print_fps ()
{
static Uint32 last_t = 0;
Uint32 t = SDL_GetTicks();
Uint32 dt = t - last_t;
t_acc += dt;
if (t_acc > 1000)
{
unsigned int el_time = t_acc / 1000;
printf("- fps: %g\n",
(float) frames / (float) el_time);
t_acc = 0;
frames = 0;
}
last_t = t;
}
void blit_noise(SDL_Surface *surf)
{
unsigned int i;
long dim = surf->w * surf->h;
while (1)
{
SDL_LockSurface(surf);
for (i=0; i < dim; ++i) {
((unsigned char *)surf->pixels)[i] = ((rand() & 1) ? 255 : 0);
}
SDL_UnlockSurface(surf);
SDL_Flip(surf);
++frames;
print_fps();
}
}
int main(void)
{
SDL_Surface *surf = NULL;
srand((unsigned int)time(NULL));
SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO);
surf = SDL_SetVideoMode(320, 240, 8, SDL_DOUBLEBUF | SDL_HWSURFACE);
blit_noise(surf);
}

View file

@ -0,0 +1,47 @@
#include <GL/glut.h>
#include <GL/gl.h>
#include <stdio.h>
#include <time.h>
#define W 320
#define H 240
#define slen W * H / sizeof(int)
time_t start, last;
void render()
{
static int frame = 0, bits[slen];
register int i = slen, r;
time_t t;
r = bits[0] + 1;
while (i--) r *= 1103515245, bits[i] = r ^ (bits[i] >> 16);
glClear(GL_COLOR_BUFFER_BIT);
glBitmap(W, H, 0, 0, 0, 0, (void*)bits);
glFlush();
if (!(++frame & 15)) {
if ((t = time(0)) > last) {
last = t;
printf("\rfps: %ld ", frame / (t - start));
fflush(stdout);
}
}
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_INDEX);
glutInitWindowSize(W, H);
glutCreateWindow("noise");
glutDisplayFunc(render);
glutIdleFunc(render);
last = start = time(0);
glutMainLoop();
return 0;
}