标题: [技术讨论] Perl 重写 OpenGL RedBook 绘制位图示例 - drawf.c [打印本页]
作者: 523066680 时间: 2017-7-22 11:33 标题: Perl 重写 OpenGL RedBook 绘制位图示例 - drawf.c
本帖最后由 523066680 于 2017-7-22 11:41 编辑
我只是看 Perl 区太空荡荡了,随便发点什么
原代码:- #include <GL/gl.h>
- #include <GL/glu.h>
- #include "aux.h"
-
- GLubyte rasters[24] = {
- 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00,
- 0xc0, 0x00, 0xff, 0x00, 0xff, 0x00, 0xc0, 0x00,
- 0xc0, 0x00, 0xc0, 0x00, 0xff, 0xc0, 0xff, 0xc0};
-
- void myinit(void)
- {
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- glClearColor(0.0, 0.0, 0.0, 0.0);
- }
-
- void display(void)
- {
- glClear(GL_COLOR_BUFFER_BIT);
- glColor3f(1.0, 1.0, 1.0);
- glRasterPos2i (20.5, 20.5);
- glBitmap(10, 12, 0.0, 0.0, 12.0, 0.0, rasters);
- glBitmap(10, 12, 0.0, 0.0, 12.0, 0.0, rasters);
- glBitmap(10, 12, 0.0, 0.0, 12.0, 0.0, rasters);
- glFlush();
- }
-
- void myReshape(GLsizei w, GLsizei h)
- {
- glViewport(0, 0, w, h);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0, w, 0, h, -1.0, 1.0);
- glMatrixMode(GL_MODELVIEW);
- }
-
-
- int main(int argc, char** argv)
- {
- auxInitDisplayMode(AUX_SINGLE | AUX_RGBA);
- auxInitPosition(0, 0, 500, 500);
- auxInitWindow(argv[0]);
- myinit();
- auxReshapeFunc(myReshape);
- auxMainLoop(display);
- }
复制代码
Perl 代码- =info
- Auth: 523066680
- Date: 2017-07
- =cut
-
- use Encode;
- use Time::HiRes qw/time sleep/;
- use OpenGL qw/ :all /;
- use OpenGL::Config;
-
- our $SIZE_X = 500;
- our $SIZE_Y = 500;
- our $WinID;
-
- &Main();
-
- sub display
- {
- glClear(GL_COLOR_BUFFER_BIT);
- my @rasters =
- (
- 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00,
- 0xc0, 0x00, 0xff, 0x00, 0xff, 0x00, 0xc0, 0x00,
- 0xc0, 0x00, 0xc0, 0x00, 0xff, 0xc0, 0xff, 0xc0
- );
-
- my $array = OpenGL::Array->new( scalar( @rasters ), GL_UNSIGNED_BYTE );
- $array->assign(0, @rasters);
-
- glRasterPos2i(0.0, 0.0);
- glBitmap_c( 10, 12, 0.0, 0.0, 12.0, 0.0, $array->ptr() );
- glBitmap_c( 10, 12, 0.0, 0.0, 12.0, 0.0, $array->ptr() );
- glBitmap_c( 10, 12, 0.0, 0.0, 12.0, 0.0, $array->ptr() );
- glutSwapBuffers();
- }
-
- sub init
- {
- glClearColor(0.0, 0.0, 0.0, 1.0);
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- }
-
- sub idle
- {
- sleep 0.1;
- glutPostRedisplay();
- }
-
- sub hitkey
- {
- my $key = shift;
- glutDestroyWindow($WinID) if ( lc(chr($key)) eq 'q' );
- }
-
- sub Main
- {
- glutInit();
- glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE );
- glutInitWindowSize($SIZE_X, $SIZE_Y);
- glutInitWindowPosition(1,1);
- our $WinID = glutCreateWindow("glBitmap");
- &init();
- glutDisplayFunc(\&display);
- glutKeyboardFunc(\&hitkey);
- glutIdleFunc(\&idle);
- glutMainLoop();
- }
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |