19 void reshape(int x, int y);
20 void keyb(unsigned char key, int x, int y);
22 int win_width, win_height;
23 int max_xscroll, max_yscroll;
27 unsigned int img[IMG_W * IMG_H];
29 int mode = MODE_DRAWPIX;
31 int main(int argc, char **argv)
33 glutInit(&argc, argv);
34 glutInitWindowSize(800, 600);
35 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
36 glutCreateWindow("GL pixel drawing methods");
38 glutDisplayFunc(display);
39 glutReshapeFunc(reshape);
40 glutKeyboardFunc(keyb);
53 int i, j, xor, r, g, b;
58 for(i=0; i<IMG_H; i++) {
59 for(j=0; j<IMG_W; j++) {
61 r = (xor >> 1) & 0xff;
63 b = (xor << 1) & 0xff;
64 *ptr++ = r | (g << 8) | (b << 16);
68 glPixelStorei(GL_UNPACK_ROW_LENGTH, IMG_W);
70 win_width = glutGet(GLUT_WINDOW_WIDTH);
71 win_height = glutGet(GLUT_WINDOW_HEIGHT);
73 glGenTextures(1, &tex);
74 glBindTexture(GL_TEXTURE_2D, tex);
75 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
76 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
77 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, win_width, win_height, 1, GL_RGBA, GL_UNSIGNED_BYTE, 0);
84 unsigned int tm = glutGet(GLUT_ELAPSED_TIME);
85 float t = tm / 256.0f;
86 int xoffs = (int)((sin(t) * 0.5f + 0.5f) * max_xscroll);
87 int yoffs = (int)((cos(t) * 0.5f + 0.5f) * max_yscroll);
92 /* draw with points */
96 /* draw with glDrawPixels */
97 start = img + yoffs * IMG_W + xoffs;
98 glDrawPixels(win_width, win_height, GL_RGBA, GL_UNSIGNED_BYTE, start);
102 /* draw with textured quad */
106 /* draw with textured triangle */
111 assert(glGetError() == GL_NO_ERROR);
119 void reshape(int x, int y)
121 glViewport(0, 0, x, y);
125 max_xscroll = IMG_W - win_width;
126 max_yscroll = IMG_H - win_height;
127 if(max_xscroll < 0) max_xscroll = 0;
128 if(max_yscroll < 0) max_yscroll = 0;
131 void keyb(unsigned char key, int x, int y)
138 mode = (mode + 1) % NUM_MODES;