944,116 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 733
  • C RSS
Mar 24th, 2007
0

my program given some erroe (computer graphics)

Expand Post »
i am just start Computer grahics. that is my first program please help me
  1. #include <GL/glut.h>
  2.  
  3. void DrawPixels();
  4. void OurPixelsDrawingFunction();
  5. void SetView();
  6.  
  7. void SetView(int w, int h)
  8. {
  9. glViewport(0,0,w,h);
  10. glMatrixMode(GL_PROJECTION);
  11. glLoadIdentity();
  12. glMatrixMode (GL_MODELVIEW);
  13. glLoadIdentity();
  14.  
  15. }
  16.  
  17. void DrawPixels()
  18. {
  19. glClearColor(1.0,1.0,1.0,0);
  20.  
  21. glClear(GL_COLOR_BUFFER_BIT);
  22.  
  23.  
  24.  
  25. glMatrixMode(GL_PROJECTION);
  26.  
  27. gluOrtho2D (0.0,600.0,0.0,600.0);
  28.  
  29.  
  30. OurPixelsDrawingFunction();
  31.  
  32.  
  33.  
  34. void OurPixelsDrawingFuntion()
  35. {
  36. glColor3f(0,1,0);
  37. /*Set current pixels drwaing color to green*/
  38. glPointSize(10);
  39. /* Sets the pixel size to 10 units*/
  40. glBegin(GL_POINTS);
  41. /* Tells the Open GL that we want to draw points, similarly we can tell OpenGL
  42. that we want to draw lines using GL_LINES and then we will use line drawing
  43. functons.*/
  44. /*====================================================================*/
  45. /* Drawing one horizental line covering full window (0 to 600) */
  46. /* at Y = 100 and x from 0 to 600 */
  47. /*====================================================================*/
  48. for(int i = 0; i <= 600; i++)
  49. glVertex2i(i,100);
  50. /*=========================================================================*/
  51.  
  52. /*=========================================================================*/
  53. /* Drawing only one pixel of blue color form zero
  54.   /*=========================================================================*/
  55. glColor3f(0,0,1);
  56. glVertex2i(140,120);
  57. /*=========================================================================*/
  58.  
  59. /*=========================================================================*/
  60. /* Drawing one Vertical line of four pixels for fourd */
  61. /*=========================================================================*/
  62. glColor3f(0,1,0);
  63. glVertex2i(160,120);
  64. glVertex2i(160,140);
  65. glVertex2i(160,160);
  66. glVertex2i(160,180);
  67. /*=========================================================================*/
  68.  
  69. /*=========================================================================*/
  70. /* Draewing only one pixel of blue color for Zero */
  71. /*=========================================================================*/
  72. glColor3f(0,0,1);
  73. glVertex2i(180,120);
  74. /*=========================================================================*/
  75. /*=========================================================================*/
  76. /* Drawing one Vertical line of Two pixels for two */
  77. /*=========================================================================*/
  78. glColor3f(0,1,0);
  79. glVertex2i(200,120);
  80. glVertex2i(200,140);
  81. /*=========================================================================*/
  82.  
  83. /*=========================================================================*/
  84. /* Drawing only one Pixel of blue color for zero */
  85.  
  86. /*=========================================================================*/
  87. glColor3f(0,0,1);
  88. glVertex2i(220,120);
  89. /*=========================================================================*/
  90.  
  91. /*=========================================================================*/
  92. /* Drawing only one pexel of blue color for zero */
  93. /*=========================================================================*/
  94. glColor3f(0,0,1);
  95. glVertex2i(240,120);
  96. /*=========================================================================*/
  97.  
  98. /*=========================================================================*/
  99. /* Drawing one Vertical line of two pexels for two */
  100. /*=========================================================================*/
  101. glColor3f(0,1,0);
  102. glVertex2i(260,120);
  103. glVertex2i(260,140);
  104. /*=========================================================================*/
  105.  
  106. /*=========================================================================*/
  107. /* drawing one Vertical line of five pixels for five */
  108. /*=========================================================================*/
  109. glColor3f(0,1,0);
  110. glVertex2i(280,120);
  111. glVertex2i(280,140);
  112. glVertex2i(280,160);
  113. glVertex2i(280,180);
  114. glVertex2i(280,200);
  115. /*=========================================================================*/
  116.  
  117. /*=========================================================================*/
  118. /* Drawing only one pexel of blue color for zero
  119.   /*=========================================================================*/
  120. glColor3f(0,0,1);
  121. glVertex2i(300,120);
  122. /*=========================================================================*/
  123.  
  124. /*=========================================================================*/
  125. /* We can use loops if we want to for this purpose as well.*/
  126. /*=========================================================================*/
  127. glEnd();
  128. /* tells Open GL that we have finished drawing pixels*/
  129.  
  130. /*=========================================================================*/
  131. /* Writng Text */
  132. /*=========================================================================*/
  133.  
  134. /*===========Write your Id=================================================*/
  135.  
  136. glRasterPos2i(140,80);
  137.  
  138. /* this pixels are wrtien using raster mod see the handouts of Lecture no. 3
  139.   for more details. In this mode we have fexed no. of horizontal and vertical
  140.   lines we can't draw pexels using this mode
  141.   */
  142.  
  143. char id[12] = "bc040200250";
  144. int id_count = (int)strlen (id);
  145. for (int i=0; i < id_count; i++)
  146. {
  147. glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, id[i]);
  148. }
  149.  
  150. glFlush();
  151. /* this command out put pexels on the screen without this commmand the pixels
  152.   will not be displayed to the screen*/
  153.  
  154. }
  155.  
  156. /*/////////////////////////////////////////////////////////////////////////////
  157.   //
  158. This is reshape function mean that this function is called whenever we resizw//
  159. our window and in this fuction we are adjusting the contents of our window //
  160. according to its new size. This function can be used in any graphics program //
  161. and you don't need to understand it thoroughly at this moment,*/ //
  162. /////////////////////////////////////////////////////////////////////////////*/
  163.  
  164.  
  165.  
  166. /*/////////////////////////////////////////////////////////////////////////*/
  167. int main (int argc ,char ** argv)
  168.  
  169. {
  170. glutInit(&argc,argv);
  171. glutInitWindowSize(800,600);
  172. glutCreateWindow ("-----bc040200250.........Your Name------");
  173. glutDisplayFunc(DrawPixels);
  174. glutReshapeFunc(SetView);
  175. glutMainLoop ();
  176. return 0;
  177. }
Last edited by ~s.o.s~; Mar 24th, 2007 at 4:22 pm. Reason: Added code tags, learn to use them.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
iqbal is offline Offline
10 posts
since Aug 2005
Mar 24th, 2007
0

Re: my program given some erroe (computer graphics)

Please use [code][/code] tags around your code.
Nobody wants to read a whole mess of unindented code.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Mar 24th, 2007
0

Re: my program given some erroe (computer graphics)

lol that was funny reading all that like that but ya i totally agree with salem
Reputation Points: 10
Solved Threads: 2
Junior Poster
grunge man is offline Offline
169 posts
since Mar 2006
Mar 24th, 2007
0

Re: my program given some erroe (computer graphics)

Some problems with your code...

First of all, what platform are you trying to compile this on? On my Mac, I include GLUT/glut.h (you had included GL/glut.h). Getting the header right removes about 8 errors.

You forgot a closing brace here:
  1. void DrawPixels()
  2. {
  3. glClearColor(1.0,1.0,1.0,0);
  4.  
  5. glClear(GL_COLOR_BUFFER_BIT);
  6.  
  7.  
  8.  
  9. glMatrixMode(GL_PROJECTION);
  10.  
  11. gluOrtho2D (0.0,600.0,0.0,600.0);
  12.  
  13.  
  14. OurPixelsDrawingFunction();
  15.  
  16. // need } here
  17.  
  18. // you forgot 'c' in 'Funtion'
  19. void OurPixelsDrawingFuntion()

Finally, to use strlen(), you must #include <cstring>. Anyway, there weren't any bugs in the program, and it ran fine after I made these minor corrections.

And this is in the wrong forum, Game Development is better suited for this...
Team Colleague
Reputation Points: 2240
Solved Threads: 338
Vampirical Lurker
John A is offline Offline
5,055 posts
since Apr 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Set combinations function
Next Thread in C Forum Timeline: can't think of a title for it





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC