Created
February 21, 2013 20:56
-
-
Save tai2/5008183 to your computer and use it in GitHub Desktop.
White noize(very slow and strange grid appeared)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <GLUT/glut.h> | |
#define SCREEN_WIDTH 640 | |
#define SCREEN_HEIGHT 360 | |
static int curr_width = 0; | |
static int curr_height = 0; | |
static void | |
keyboard(unsigned char c, int x, int y) | |
{ | |
switch (c) { | |
case 27: /* Esc key */ | |
exit(0); | |
break; | |
} | |
} | |
void | |
idle() | |
{ | |
glutPostRedisplay(); | |
} | |
static void | |
reshape(int w, int h) | |
{ | |
curr_width = w; | |
curr_height = h; | |
} | |
// Okay... Iknow this is stupid way to draw a pixel. | |
static void | |
draw_pixel(int x, int y, float r, float g, float b) | |
{ | |
glColor3f(r, g, b); | |
glPointSize(1); | |
glPushMatrix(); { | |
glBegin(GL_POINTS); | |
glVertex2f(x, y); | |
glEnd(); | |
} glPopMatrix(); | |
} | |
static void | |
display() | |
{ | |
int x, y; | |
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); | |
glViewport(0, 0, curr_width, curr_height); | |
glMatrixMode(GL_PROJECTION); | |
glLoadIdentity(); | |
gluOrtho2D(0, SCREEN_WIDTH, 0, SCREEN_HEIGHT); | |
glMatrixMode(GL_MODELVIEW); | |
glLoadIdentity(); | |
for (y = 0; y < SCREEN_HEIGHT; y++) { | |
for (x = 0; x < SCREEN_WIDTH; x++) { | |
float v = (float)rand() / RAND_MAX; | |
draw_pixel(x, y, v, v, v); | |
} | |
} | |
glutSwapBuffers(); | |
} | |
int | |
main(int argc, char** argv) | |
{ | |
srand(0); | |
glutInit(&argc, argv); | |
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH ); | |
glutInitWindowSize(SCREEN_WIDTH, SCREEN_HEIGHT); | |
glutInitWindowPosition(100, 100); | |
glutCreateWindow(argv[0]); | |
glutKeyboardFunc(keyboard); | |
glutIdleFunc(idle); | |
glutReshapeFunc(reshape); | |
glutDisplayFunc(display); | |
glutFullScreen(); | |
glClearColor(0.0, 0.0, 0.0, 0.0); | |
glShadeModel(GL_SMOOTH); | |
glDisable(GL_DEPTH_TEST); | |
glDisable(GL_LIGHTING); | |
glCullFace(GL_BACK); | |
glEnable(GL_CULL_FACE); | |
glutMainLoop(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment