免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 3790 | 回复: 10
打印 上一主题 下一主题

[C] linux下面如何点亮一个像素? [复制链接]

论坛徽章:
3
寅虎
日期:2013-11-27 07:53:29申猴
日期:2014-09-12 09:24:152015年迎新春徽章
日期:2015-03-04 09:48:31
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-01-11 22:51 |只看该作者 |倒序浏览
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
36
子鼠
日期:2013-08-28 22:23:29黄金圣斗士
日期:2015-12-01 11:37:51程序设计版块每日发帖之星
日期:2015-12-14 06:20:00CU十四周年纪念徽章
日期:2015-12-22 16:50:40IT运维版块每日发帖之星
日期:2016-01-25 06:20:0015-16赛季CBA联赛之深圳
日期:2016-01-27 10:31:172016猴年福章徽章
日期:2016-02-18 15:30:3415-16赛季CBA联赛之福建
日期:2016-04-07 11:25:2215-16赛季CBA联赛之青岛
日期:2016-04-29 18:02:5915-16赛季CBA联赛之北控
日期:2016-06-20 17:38:50技术图书徽章
日期:2016-07-19 13:54:03程序设计版块每日发帖之星
日期:2016-08-21 06:20:00
2 [报告]
发表于 2013-01-11 23:17 |只看该作者
回复 1# Sevk


    看OpenGL吧

论坛徽章:
3
寅虎
日期:2013-11-27 07:53:29申猴
日期:2014-09-12 09:24:152015年迎新春徽章
日期:2015-03-04 09:48:31
3 [报告]
发表于 2013-01-12 14:26 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
3
寅虎
日期:2013-11-27 07:53:29申猴
日期:2014-09-12 09:24:152015年迎新春徽章
日期:2015-03-04 09:48:31
4 [报告]
发表于 2013-01-12 15:14 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
5 [报告]
发表于 2013-01-13 23:28 |只看该作者
Framebuffer,

这个简单

论坛徽章:
5
技术图书徽章
日期:2013-08-17 07:26:49双子座
日期:2013-09-15 16:46:29双子座
日期:2013-09-25 08:17:09技术图书徽章
日期:2013-09-25 09:11:42天秤座
日期:2013-10-01 16:25:34
6 [报告]
发表于 2013-01-13 23:31 |只看该作者

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>

  4. #include <GL/glut.h>

  5. #define WINDOW_WIDTH 600
  6. #define WINDOW_HEIGHT 640
  7. #define WINDOW_X 200
  8. #define WINDOW_Y 200

  9. #define FRAME_PER_SECOND 20
  10. #define KEY_EXIT 27

  11. #define POINT_NUM 288
  12. #define MATRIX_NUM 8

  13. typedef struct bgPoint
  14. {
  15.         float x, y;
  16.         float vx, vy;
  17.         int r, g, b;
  18. }BGPoint;
  19. typedef BGPoint* Point;
  20. typedef struct bgMatrix
  21. {
  22.         BGPoint point[POINT_NUM];

  23.         int timer;
  24.         int targetTime;
  25.         int pauseTime;
  26. }BGMatrix;
  27. typedef BGMatrix* Matrix;

  28. Matrix* matrices;

  29. #define bgRand(m) ((float)(rand() % 10000) * m / 10000.0f)

  30. void handleKeyEvent(unsigned char key, int x, int y);
  31. void handleMouseEvent(int button, int state, int x, int y);
  32. void handleReshape(int width, int height);

  33. void run(int null);
  34. void update(void);
  35. void repaint(void);

  36. void initScene(void);
  37. void doScene(void);
  38. void drawScene(void);
  39. void exitScene(void);

  40. void initMatrices(void);
  41. void doMatrices(void);
  42. void drawMatrices(void);
  43. void exitMatrices(void);

  44. Matrix initMatrix(int matrixId);
  45. void doMatrix(int matrixId);
  46. void drawMatrix(int matrixId);
  47. void exitMatrix(int matrixId);

  48. void sleepMilliSeconds(long milliSeconds);

  49. int main(int argc, char ** argv)
  50. {
  51.         glutInit(&argc, argv);
  52.         glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  53.         glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
  54.         glutInitWindowPosition(WINDOW_X, WINDOW_Y);
  55.         glutCreateWindow("BestMatrix");

  56.         glutKeyboardFunc(handleKeyEvent);
  57.         glutMouseFunc(handleMouseEvent);
  58.         glutReshapeFunc(handleReshape);

  59.         initScene();

  60.         glutDisplayFunc(repaint);
  61.         glutTimerFunc(FRAME_PER_SECOND, run, 0);

  62.         glutMainLoop();

  63.         return 0;   
  64. }

  65. void run(int null)
  66. {   
  67.         clock_t startTime, endTime;

  68.         startTime = clock();

  69.         update();
  70.         repaint();

  71.         endTime = clock();

  72.         if (endTime - startTime < FRAME_PER_SECOND)
  73.         {
  74.                 sleepMilliSeconds(FRAME_PER_SECOND - (endTime - startTime));
  75.         }

  76.         glutPostRedisplay();
  77.         glutTimerFunc(FRAME_PER_SECOND, run, 0);        
  78. }

  79. void update(void)
  80. {
  81.         doScene();
  82. }

  83. void repaint(void)
  84. {
  85.         glClear(GL_COLOR_BUFFER_BIT);

  86.         drawScene();

  87.         glutSwapBuffers();
  88. }

  89. void initScene(void)
  90. {
  91.         srand(time(0));

  92.         initMatrices();

  93.         glPointSize(2.0);
  94.         glMatrixMode (GL_PROJECTION);
  95.         glLoadIdentity ();
  96.         gluOrtho2D(0, (GLdouble)WINDOW_WIDTH, 0, (GLdouble)WINDOW_HEIGHT);
  97.         glClearColor(0.0, 0.0, 0.0, 0.0);
  98.         glShadeModel(GL_FLAT);
  99.         glEnable(GL_COLOR_MATERIAL);

  100. }

  101. void doScene(void)
  102. {
  103.         doMatrices();
  104. }

  105. void drawScene(void)
  106. {
  107.         drawMatrices();
  108. }

  109. void exitScene(void)
  110. {
  111.         exitMatrices();
  112.         exit(0);
  113. }

  114. void initMatrices(void)
  115. {
  116.         int i;

  117.         matrices  = malloc(sizeof(Matrix) * MATRIX_NUM);

  118.         for (i = 0; i < MATRIX_NUM; i++)
  119.         {
  120.                 matrices[i] = initMatrix(i);
  121.         }
  122. }

  123. void doMatrices(void)
  124. {
  125.         int i = 0;

  126.         for (i = 0; i < MATRIX_NUM; i++)
  127.         {
  128.                 doMatrix(i);
  129.         }
  130. }

  131. void drawMatrices(void)
  132. {
  133.         int i;

  134.         for (i = 0; i < MATRIX_NUM; i++)
  135.         {
  136.                 drawMatrix(i);
  137.         }
  138. }

  139. void exitMatrices(void)
  140. {
  141.         int i;

  142.         for (i = 0; i < MATRIX_NUM; i++)
  143.         {
  144.                 exitMatrix(i);
  145.         }
  146. }

  147. Matrix initMatrix(int matrixId)
  148. {
  149.         Matrix matrix;
  150.         float x, y;
  151.         int r, g, b;
  152.         int i;


  153.         matrix = malloc(sizeof(BGMatrix));

  154.         matrix->timer = 0;
  155.         matrix->targetTime = rand()%50;
  156.         matrix->pauseTime = 50;

  157.         x = 20.0f + bgRand(600.0f);
  158.         y = 100.f + bgRand(100.0f);
  159.         r = 50 + rand()%(255-50);
  160.         g = 50 + rand()%(255-50);
  161.         b = 50 + rand()%(255-50);

  162.         for (i = 0; i < POINT_NUM; i++)
  163.         {
  164.                 matrix->point[i].x = x;
  165.                 matrix->point[i].y = y;
  166.                 matrix->point[i].vx = 1.0f - bgRand(2.0f);
  167.                 matrix->point[i].vy = 1.0f - bgRand(2.0f);
  168.                 matrix->point[i].r = r;
  169.                 matrix->point[i].g = g;
  170.                 matrix->point[i].b = b;
  171.         }

  172.         return matrix;
  173. }

  174. void doMatrix(int matrixId)
  175. {
  176.         int i;

  177.         if (matrices[matrixId]->timer++ > matrices[matrixId]->targetTime)
  178.         {
  179.                 for (i = 0; i < POINT_NUM; i++)
  180.                 {
  181.                         //matrices[matrixId]->point[i].vy += 0.1f;
  182.                         matrices[matrixId]->point[i].x += matrices[matrixId]->point[i].vx;
  183.                         matrices[matrixId]->point[i].y += matrices[matrixId]->point[i].vy;
  184.                 }
  185.         }

  186.         if (matrices[matrixId]->timer > matrices[matrixId]->targetTime + matrices[matrixId]->pauseTime)
  187.         {
  188.                 exitMatrix(matrixId);
  189.                 matrices[matrixId] = initMatrix(matrixId);
  190.         }
  191. }

  192. void drawMatrix(int matrixId)
  193. {
  194.         int i;

  195.         unsigned char r, g, b;

  196.         glBegin(GL_POINTS);

  197.         for (i = 0; i < POINT_NUM; i++)
  198.         {
  199.                 r = matrices[matrixId]->point[i].r;
  200.                 g = matrices[matrixId]->point[i].g;
  201.                 b = matrices[matrixId]->point[i].b;

  202.                 glColor3ub(r, g, b);
  203.                 glVertex2f(matrices[matrixId]->point[i].x, WINDOW_HEIGHT - matrices[matrixId]->point[i].y);
  204.         }

  205.         glEnd();
  206. }

  207. void exitMatrix(int matrixId)
  208. {
  209.         free(matrices[matrixId]);
  210. }

  211. void handleKeyEvent(unsigned char key, int x, int y)
  212. {
  213.         switch (key)
  214.         {
  215.                 case KEY_EXIT:
  216.                         exitScene();
  217.                         break;

  218.                 default:
  219.                         break;
  220.         }
  221. }

  222. void handleMouseEvent(int button, int state, int x, int y)
  223. {
  224.         switch (button)
  225.         {
  226.                 case GLUT_LEFT_BUTTON:
  227.                         if (state == GLUT_DOWN)
  228.                                 glutIdleFunc(repaint);
  229.                         break;

  230.                 case GLUT_RIGHT_BUTTON:
  231.                         if (state == GLUT_DOWN)
  232.                                 glutIdleFunc(NULL);
  233.                         break;

  234.                 default:
  235.                         break;
  236.         }
  237. }

  238. void handleReshape(int width, int height)
  239. {
  240.         glViewport(0, 0, width, height);
  241.         glMatrixMode(GL_PROJECTION);
  242.         glLoadIdentity();
  243.         gluOrtho2D(0, (GLdouble)width, 0, (GLdouble)height);
  244. }

  245. void sleepMilliSeconds(long milliSeconds)
  246. {
  247.         clock_t start, end;

  248.         start = clock();
  249.         end  = start + milliSeconds;

  250.         while (start < end)
  251.         {
  252.                 start = clock();
  253.         }
  254. }
复制代码

论坛徽章:
0
7 [报告]
发表于 2013-01-14 08:48 |只看该作者
Sevk 发表于 2013-01-12 15:14
我想写个桌面下雪的小程序, 是否有现成的,我学习一下。

除了opengl, 兼容gnome, kde的还有 xlib , fra ...

Compiz Fusion的plugins

论坛徽章:
3
寅虎
日期:2013-11-27 07:53:29申猴
日期:2014-09-12 09:24:152015年迎新春徽章
日期:2015-03-04 09:48:31
8 [报告]
发表于 2013-01-14 21:47 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
3
寅虎
日期:2013-11-27 07:53:29申猴
日期:2014-09-12 09:24:152015年迎新春徽章
日期:2015-03-04 09:48:31
9 [报告]
发表于 2013-01-15 20:04 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
10 [报告]
发表于 2013-01-16 16:53 |只看该作者
Sevk 发表于 2013-01-12 15:14
我想写个桌面下雪的小程序, 是否有现成的,我学习一下。

除了opengl, 兼容gnome, kde的还有 xlib , fra ...


xsnow
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP