Board logo

标题: [技术讨论] Perl 重写 OpenGL RedBook 绘制位图示例 - drawf.c [打印本页]

作者: 523066680    时间: 2017-7-22 11:33     标题: Perl 重写 OpenGL RedBook 绘制位图示例 - drawf.c

本帖最后由 523066680 于 2017-7-22 11:41 编辑

我只是看 Perl 区太空荡荡了,随便发点什么

原代码:
  1. #include <GL/gl.h>
  2. #include <GL/glu.h>
  3. #include "aux.h"
  4. GLubyte rasters[24] = {
  5.     0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00,
  6.     0xc0, 0x00, 0xff, 0x00, 0xff, 0x00, 0xc0, 0x00,
  7.     0xc0, 0x00, 0xc0, 0x00, 0xff, 0xc0, 0xff, 0xc0};
  8. void myinit(void)
  9. {
  10.     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  11.     glClearColor(0.0, 0.0, 0.0, 0.0);
  12. }
  13. void display(void)
  14. {
  15.     glClear(GL_COLOR_BUFFER_BIT);
  16.     glColor3f(1.0, 1.0, 1.0);
  17.     glRasterPos2i (20.5, 20.5);
  18.     glBitmap(10, 12, 0.0, 0.0, 12.0, 0.0, rasters);
  19.     glBitmap(10, 12, 0.0, 0.0, 12.0, 0.0, rasters);
  20.     glBitmap(10, 12, 0.0, 0.0, 12.0, 0.0, rasters);
  21.     glFlush();
  22. }
  23. void myReshape(GLsizei w, GLsizei h)
  24. {
  25.     glViewport(0, 0, w, h);
  26.     glMatrixMode(GL_PROJECTION);
  27.     glLoadIdentity();
  28.     glOrtho(0, w, 0, h, -1.0, 1.0);
  29.     glMatrixMode(GL_MODELVIEW);
  30. }
  31. int main(int argc, char** argv)
  32. {
  33.     auxInitDisplayMode(AUX_SINGLE | AUX_RGBA);
  34.     auxInitPosition(0, 0, 500, 500);
  35.     auxInitWindow(argv[0]);
  36.     myinit();
  37.     auxReshapeFunc(myReshape);
  38.     auxMainLoop(display);
  39. }
复制代码
Perl 代码
  1. =info
  2.     Auth: 523066680
  3.     Date: 2017-07
  4. =cut
  5. use Encode;
  6. use Time::HiRes qw/time sleep/;
  7. use OpenGL qw/ :all /;
  8. use OpenGL::Config;
  9. our $SIZE_X = 500;
  10. our $SIZE_Y = 500;
  11. our $WinID;
  12. &Main();
  13. sub display
  14. {
  15.     glClear(GL_COLOR_BUFFER_BIT);
  16.     my @rasters =
  17.         (
  18.             0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00,
  19.             0xc0, 0x00, 0xff, 0x00, 0xff, 0x00, 0xc0, 0x00,
  20.             0xc0, 0x00, 0xc0, 0x00, 0xff, 0xc0, 0xff, 0xc0
  21.         );
  22.     my $array = OpenGL::Array->new( scalar( @rasters ), GL_UNSIGNED_BYTE );
  23.     $array->assign(0, @rasters);
  24.     glRasterPos2i(0.0, 0.0);
  25.     glBitmap_c( 10, 12, 0.0, 0.0, 12.0, 0.0, $array->ptr() );
  26.     glBitmap_c( 10, 12, 0.0, 0.0, 12.0, 0.0, $array->ptr() );
  27.     glBitmap_c( 10, 12, 0.0, 0.0, 12.0, 0.0, $array->ptr() );
  28.     glutSwapBuffers();
  29. }
  30. sub init
  31. {
  32.     glClearColor(0.0, 0.0, 0.0, 1.0);
  33.     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  34. }
  35. sub idle
  36. {
  37.     sleep 0.1;
  38.     glutPostRedisplay();
  39. }
  40. sub hitkey
  41. {
  42.     my $key = shift;
  43.     glutDestroyWindow($WinID) if ( lc(chr($key)) eq 'q' );
  44. }
  45. sub Main
  46. {
  47.     glutInit();
  48.     glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE );
  49.     glutInitWindowSize($SIZE_X, $SIZE_Y);
  50.     glutInitWindowPosition(1,1);
  51.     our $WinID = glutCreateWindow("glBitmap");
  52.     &init();
  53.     glutDisplayFunc(\&display);
  54.     glutKeyboardFunc(\&hitkey);
  55.     glutIdleFunc(\&idle);
  56.     glutMainLoop();
  57. }
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2