Compiling OpenGL in Linux

Source: Internet
Author: User

Configuring mesa3d in Ubuntu is simple and does not have to be as tedious as in windows.
I fully use the new version, which is more in line with my windows usage habits.
In Linux, open-source mesa3d is used to replace OpenGL APIs, while freeglut is used for glut.
Find the mesa3d Dev package in the new, note that it is not the runtime package (this package is installed by default, do not accidentally Uninstall.). Then there is a freeglut3-dev. Installation on it, letProgramThe dependency issue is automatically handled. After both are installed, find a compiler and test it.


// HW. c
# Include <Gl/glut. h> // same as in windows, glut. h itself includes Gl. h and Glu. h.

void display ()
{< br> glclear (gl_color_buffer_bit);
glbegin (gl_polygon);
glvertex2f (-0.5, -0.5);
glvertex2f (0.5,-0.5);
glvertex2f (0.5, 0.5);
glvertex2f (-0.5, 0.5 );
glend ();
glflush ();
}< br> int main (INT argc, char ** argv)
{< br> gluinit (& argc, argv);
glucreatewindow ("SP");
gludisplayfunc (Display);
glumainloop ();
return 0;
}< br>

compile GCC.
gcc hw. c-o HW-lglut
-lglut is the library file of the glut used.
then run the file
. /HW
if you see a white square in a small black window, it means the operation is successful. note that compiz needs to be closed during running; otherwise, the window will flash and disappear.

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.