Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
50
Task/Image-noise/C/image-noise-1.c
Normal file
50
Task/Image-noise/C/image-noise-1.c
Normal 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);
|
||||
}
|
||||
47
Task/Image-noise/C/image-noise-2.c
Normal file
47
Task/Image-noise/C/image-noise-2.c
Normal 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue