How to set the OpenGL programming environment in Linux

Source: Internet
Author: User
Install freeglut or mesa first. Take freeglut as an example. after installation, gluth will appear in usrshortdegl and libgluso will appear in usrlib. if not, copy it yourself.

Install freeglut or mesa first.

Take freeglut as an example. after installation, glut. h will appear in/usr/include/GL and libglut. so will appear in/usr/lib. if not, copy it yourself.

Then write a test program, such as test. c, and compile it with the following command:

Gcc-lglut test. c-o test

Generate the executable file test, and then:

./Test

If the box is displayed, the installation is successful :)

If there are no existing test examples in hand, the attachment is the first example of openGL Redbook hello. c

  1. # Include
  2. Void display (void)
  3. {
  4. /* Clear all pixels */
  5. GlClear (GL_COLOR_BUFFER_BIT );
  6. /* Draw white polygon (rectangle) with corners
  7. * (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0)
  8. */
  9. GlColor3f (1.0, 1.0, 1.0 );
  10. GlBegin (GL_POLYGON );
  11. GlVertex3f (0.25, 0.25, 0.0 );
  12. GlVertex3f (0.75, 0.25, 0.0 );
  13. GlVertex3f (0.75, 0.75, 0.0 );
  14. GlVertex3f (0.25, 0.75, 0.0 );
  15. GlEnd ();
  16. /* Don't wait!
  17. * Start processing buffered OpenGL routines
  18. */
  19. GlFlush ();
  20. }
  21. Void init (void)
  22. {
  23. /* Select clearing color */
  24. GlClearColor (0.0, 0.0, 0.0, 0.0 );
  25. /* Initialize viewing values */
  26. GlMatrixMode (GL_PROJECTION );
  27. GlLoadIdentity ();
  28. GlOrtho (0.0, 1.0, 0.0, 1.0,-1.0, 1.0 );
  29. }
  30. /*
  31. * Declare initial window size, position, and display mode
  32. * (Single buffer and RGBA). Open window with "hello"
  33. * In its title bar. Call initialization routines.
  34. * Register callback function to display graphics.
  35. * Enter main loop and process events.
  36. */
  37. Int main (int argc, char ** argv)
  38. {
  39. Gluinit (& argc, argv );
  40. Fig );
  41. Gluinitwindowsize (250,250 );
  42. Gluinitwindowposition (100,100 );
  43. Fig ("hello ");
  44. Init ();
  45. Gludisplayfunc (display );
  46. Glumainloop ();
  47. Return 0;/* ansi c requires main to return int .*/
  48. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.