佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 921|回复: 6

谁会用visual C++ 画圆圈?

[复制链接]
发表于 10-10-2008 03:44 PM | 显示全部楼层 |阅读模式
如上....请各位帮帮忙
回复

使用道具 举报


ADVERTISEMENT

发表于 10-10-2008 08:18 PM | 显示全部楼层
画在DOS吗?
回复

使用道具 举报

 楼主| 发表于 10-10-2008 08:31 PM | 显示全部楼层
好像是的,因为时我朋友问的
回复

使用道具 举报

发表于 12-10-2008 10:57 PM | 显示全部楼层
visual c++ 需要一个graphic library。。。。
回复

使用道具 举报

发表于 14-10-2008 05:39 PM | 显示全部楼层
C++ 可能放图片吗?

用来做background
回复

使用道具 举报

发表于 16-10-2008 11:00 PM | 显示全部楼层
  1. #include <Gl/glut.h>

  2. #include <stdlib.h>
  3. #include <math.h>




  4. class screenPt
  5. {
  6. private:
  7. int x, y;


  8. public:
  9. screenPt() {
  10. x = y = 0;   //default constructor
  11. }


  12. void setCoords(int xCoordValue, int yCoordValue){
  13. x = xCoordValue;
  14. y = yCoordValue;
  15. }


  16. int getx() const {
  17. return x;
  18. }


  19. int gety() const {
  20. return y;
  21. }


  22. void incrementx() {
  23. x++;
  24. }


  25. void decrementy() {
  26. y--;
  27. }


  28. };










  29. //=================================================================================================================
  30. void Init() //initialise the function to display
  31. {
  32. glClearColor(0.0,0.0,0.0,0.0); //set the background color to black
  33. glMatrixMode(GL_PROJECTION); //set projection parameter
  34. gluOrtho2D(0.0, 300.0, 0.0, 300.0);
  35. }
  36. //=================================================================================================================






  37. //=================================================================================================================
  38. void setPixel(GLint xCoord,GLint yCoord)
  39. {
  40. glBegin(GL_POINTS);
  41. glVertex2i(xCoord, yCoord);
  42. glEnd();
  43. }
  44. //=================================================================================================================




  45. //=================================================================================================================
  46. //Circle Midpoint function
  47. void circleMidpoint(int xc,int yc, int radius)
  48. {
  49.    screenPt circPt;
  50. GLint p = 1 - radius;
  51. circPt.setCoords(0, radius);
  52.         
  53. void circlePlotPoints(int,int, screenPt);
  54.         circlePlotPoints(xc,yc, circPt);
  55. while (circPt.getx()<circPt.gety())
  56. {
  57.    circPt.incrementx();
  58. if(p < 0)
  59. p += 2 * circPt.getx() + 1;
  60. else
  61. {
  62. circPt.decrementy();
  63.                   p += 2 * (circPt.getx() - circPt.gety()) + 1;
  64. }
  65.             circlePlotPoints(xc,yc, circPt);
  66. }
  67. }
  68. //=================================================================================================================




  69. //=================================================================================================================
  70. //Circle Plotpoints
  71. void circlePlotPoints(int xc, int yc, screenPt circPt)
  72.     {
  73. setPixel(xc + circPt.getx(),yc + circPt.gety());
  74. setPixel(xc - circPt.getx(),yc + circPt.gety());
  75. setPixel(xc + circPt.getx(),yc - circPt.gety());
  76. setPixel(xc - circPt.getx(),yc - circPt.gety());
  77. setPixel(xc + circPt.gety(),yc + circPt.getx());
  78. setPixel(xc - circPt.gety(),yc + circPt.getx());
  79. setPixel(xc + circPt.gety(),yc - circPt.getx());
  80. setPixel(xc - circPt.gety(),yc - circPt.getx());
  81. }
  82. //=================================================================================================================


  83. //=================================================================================================================
  84. //The function for clearing the screen and loading the data into the frame buffer
  85. void circleDraw(void)
  86. {
  87. glClear(GL_COLOR_BUFFER_BIT);      //clears display window
  88. glPointSize(10);                    //sets point size for use by GL_POINTS
  89. glColor3f(1.0, 0.0, 0.0);          //sets colour to red
  90. circleMidpoint(150,150,100);  //call to the function 'lineBres' which performs calculation for the Bressenham algorithm
  91. glFlush();   //process all OpenGL routines as quickly as possible
  92. }
  93. //=================================================================================================================






  94. //=================================================================================================================
  95. //The main function
  96. int main(int argc, char **argv)
  97. {
  98.    
  99. glutInit(&argc, argv); //initailize  GLUT
  100. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); //set display mode
  101. glutInitWindowPosition(440,200); // sets the display window position
  102. glutInitWindowSize(400,400); //set display window width and height
  103. glutCreateWindow("Circle Drawing Program in OpenGL"); //create display window with the name in the argument




  104. Init(); //execute initialization procedure - preparing the screen
  105. glutDisplayFunc(circleDraw); //set graphic  to display window
  106. glutMainLoop(); //display everything and wait - runs a loop so that the output can be seen by the user
  107. return 0;
  108. }
复制代码
这是用open gl 画的,建议用dev c++来compile , Vc++要加入opengl32.lib , glut.lib , glut32.lib这三个library.

另外也有dos 版的,要TC3 才可以执行,比较麻烦。
所以建议用以上这个。
回复

使用道具 举报

Follow Us
 楼主| 发表于 18-10-2008 03:54 PM | 显示全部楼层
可以了!谢谢!
回复

使用道具 举报

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

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 8-6-2024 07:57 AM , Processed in 0.061288 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表