| 发表于:2007-01-02 23:05:34 楼主 |
#include <gl/glut.h> #include <stdlib.h> #include <stdio.h> static float rotangle = 0.; /* initialize antialiasing for rgba mode, including alpha * blending, hint, and line width. print out implementation * specific info on line width granularity and width. */ void init(void) { glfloat values[2]; glgetfloatv (gl_line_width_granularity, values); printf ( "gl_line_width_granularity value is %3.1f\n ", values[0]); glgetfloatv (gl_line_width_range, values); printf ( "gl_line_width_range values are %3.1f %3.1f\n ", values[0], values[1]); glenable (gl_line_smooth); glenable (gl_blend); glblendfunc (gl_src_alpha, gl_one_minus_src_alpha); glhint (gl_line_smooth_hint, gl_dont_care); gllinewidth (1.5); glclearcolor(0.0, 0.0, 0.0, 0.0); } /* draw 2 diagonal lines to form an x */ void display(void) { glclear(gl_color_buffer_bit); glcolor3f (0.0, 1.0, 0.0); glpushmatrix(); glrotatef(-rotangle, 0.0, 0.0, 0.1); glbegin (gl_lines); glvertex2f (-0.5, 0.5); glvertex2f (0.5, -0.5); glend (); glpopmatrix(); glcolor3f (0.0, 0.0, 1.0); glpushmatrix(); glrotatef(rotangle, 0.0, 0.0, 0.1); glbegin (gl_lines); glvertex2f (0.5, 0.5); glvertex2f (-0.5, -0.5); glend (); glpopmatrix(); glflush(); } void reshape(int w, int h) { glviewport(0, 0, w, h); glmatrixmode(gl_projection); glloadidentity(); if (w <= h) gluortho2d (-1.0, 1.0, -1.0*(glfloat)h/(glfloat)w, 1.0*(glfloat)h/(glfloat)w); else gluortho2d (-1.0*(glfloat)w/(glfloat)h, 1.0*(glfloat)w/(glfloat)h, -1.0, 1.0); glmatrixmode(gl_modelview); glloadidentity(); } void keyboard(unsigned char key, int x, int y) { switch (key) { case 'r ': case 'r ': rotangle += 20.; if (rotangle > = 360.) rotangle = 0.; glutpostredisplay(); break; case 27: /* escape key */ exit(0); break; default: break; } } /* main loop * open window with initial window size, title bar, * rgba display mode, and handle input events. */ int main(int argc, char** argv) { glutinit(&argc, argv); glutinitdisplaymode (glut_single ¦ glut_rgb); glutinitwindowsize (200, 200); glutcreatewindow (argv[0]); init(); glutreshapefunc (reshape); glutkeyboardfunc (keyboard); glutdisplayfunc (display); glutmainloop(); return 0; } 编译的时候不会报错,但运行是会出现 未找到msvcr80d.dll 的错误,哪位大虾能给俺解释一下呀。 (此程序的目的是绘制两条交叉的对角线,运行时可以按r键来旋转这两条直线,一观察在不同斜率下,直线的反走样效果)。 这是openggl编程指南上的例题程序,不知怎么回事运行不出来。而且还有一些运行不出来,哪位看过此书的大虾给咱解释一下。 |
|
|
|
|