A simple OpenGL program

Source: Internet
Author: User

A simple OpenGL program

 

 

Cheungmine

2009-2

 

This is a Windows console program. Create an empty project, add the following files, and compile the project. You need to change the path "../?".

 

Dependent library directory

+ --- Win_opengl32/

|

+ --- INC/

| --- Gl. H, Glu. H, glut. h

|

+ --- Lib/

| --- Glu32.lib, opengl32.lib, glu32.lib, and glut. Def

|

+ --- Bin/

| --- Glu32.dll, glu32.dll, opengl32.dll

 

 

// <Br/> // tutorial_01.c <br/> // Memory leakage detection <br/> // place the statement in the desired location: <br/> // _ crtdumpmemoryleaks (); <br/> // The Order of the following three sentences cannot be changed <br/> # DEFINE _ crtdbg_map_alloc <br/> # include <stdlib. h> <br/> # include <crtdbg. h> </P> <p> # include <stdio. h> <br/> # include <string. h> <br/> # include <math. h> <br/> # include <assert. h> </P> <p> # include <windows. h> </P> <p> // using use_sgi_opengl may run wglmakecurrent series functions on some machines to return failed results <br/> # define glu_no_lib_pragma </P> <p> // # define use_sgi_opengl <br/> # ifdef use_sgi_opengl <br/> # include ".. /.. /sgi-opengl2-sdk/include/Gl/GL. H "<br/> # include ".. /.. /sgi-opengl2-sdk/include/Gl/Glu. H "<br/> # include ".. /.. /sgi-opengl2-sdk/include/Gl/glut. H "</P> <p> # pragma comment (Lib ,".. /.. /sgi-opengl2-sdk/lib/OpenGL. lib ") <br/> # pragma comment (Lib ,".. /.. /sgi-opengl2-sdk/lib/Glu. lib ") <br/> # pragma comment (Lib ,".. /.. /sgi-opengl2-sdk/lib/glut. lib ") <br/> # else <br/> # include ".. /.. /win-opengl32/INC/GL. H "<br/> # include ".. /.. /win-opengl32/INC/Glu. H "</P> <p> # pragma comment (Lib ,".. /.. /win-opengl32/lib/opengl32.lib ") <br/> # pragma comment (Lib ,".. /.. /win-opengl32/lib/glu32.lib) </P> <p> # include ".. /.. /win-opengl32/INC/glut. H "<br/> # pragma comment (Lib ,".. /.. /win-opengl32/lib/glu32.lib ") <br/> # endif </P> <p> void _ display (void) <br/>{< br/> glclear (gl_color_buffer_bit); <br/> glcolor3f (1.0, 1.0, 1.0); <br/> glbegin (gl_polygon ); <br/> glvertex3f (0.25, 0.25, 0.0); <br/> glvertex3f (0.75, 0.25, 0.0); <br/> glvertex3f (0.75, 0.75, 0.0 ); <br/> glvertex3f (0.25, 0.75, 0.0); <br/> glend (); <br/> glflush (); <br/>}</P> <p> void _ Init (void) <br/>{< br/> glclearcolor (0.0, 0.0, 0.0, 0.0 ); <br/> glmatrixmode (gl_projection); <br/> glloadidentity (); <br/> glortho (0.0, 1.0, 0.0, 1.0,-1.0, 1.0 ); <br/>}</P> <p> int main (INT argc, char ** argv) <br/>{< br/> gluinit (& argc, argv ); <br/> gluinitdisplaymode (glu_single | glu_rgb); <br/> gluinitwindowsize (250,250); <br/> gluinitwindowposition (100,100); <br/> glucreatewindow ("hello "); <br/> _ Init (); <br/> gludisplayfunc (_ display); <br/> glumainloop (); </P> <p> _ crtdumpmemoryleaks (); <br/> return 0; <br/>}

 

Running result:

 

 

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.