In the previous blog, I posted some differences between drawing graphical functions in OpenGL and showed different functions in the same group of data. The blog address is http://www.5dkx.com/arch/138.html.
In this article, we provide the specific OpenGL program code for implementing the previous blog.
Below is the program list
// Triangle. cpp: defines the entry point of the console application.
//
/*
File: huizhi. cpp
Done: use OpenGL to draw ry
Author: www.5dkx.com
Date: 2010-3-18
*/
# Include "windows. H"
# Include "Gl/Gl. H"
# Include "Gl/Glaux. H"
# Include "Gl/Glu. H"
# Pragma comment (Lib, "opengl32.lib ")
# Pragma comment (Lib, "Glaux. lib ")
# Pragma comment (Lib, "glu32.lib ");
Void myinit ();
Void callback myreshape (glsizei W, glsizei H );
Void mydraw ();
Void callback mydisplay ();
Int main ()
{
Myinit ();
Auxreshapefunc (myreshape );
Auxmainloop (mydisplay );
Return 0;
}
Void myinit ()
{
Auxinitdisplaymode (aux_single | aux_rgba );
Auxinitposition (100,100,500,500 );
Auxinit0000wa ("test ");
Glclearcolor (0., 0.0, 0.0, 0.0 );
Glclear (gl_color_buffer_bit );
}
Void callback myreshape (glsizei W, glsizei H)
{
Glviewport (0, 0, W, H );
Glmatrixmode (gl_projection );
Glloadidentity ();
GlMatrixMode (GL_MODELVIEW );
}
Void CALLBACK MyDisplay ()
{
GlClearColor (0, 0.0, 0.0, 0.0 );
GlClear (GL_COLOR_BUFFER_BIT );
MyDraw ();
GlFlush ();
}
Void MyDraw ()
{
GLfloat Vertex [] [2] ={{-0.0, 0.8 },{ 0.5, 0.8 },{ 0.75, 0.0 },{ 0.5,-0.5 }};
GlBegin (GL_TRIANGLE_STRIP); // you can use OpenGL to plot geometric functions.
GlVertex2f (-0.5, 0.0 );
GlVertex2f (-0.4, 0.5 );
For (int I = 0; I <4; I ++)
{
// GlColor3f (0.1, GLfloat (I/10), 0.1 );
GlVertex2fv (Vertex [I]);
// Sleep (1, 5000 );
}
GlEnd ();
}
Initial: http://www.5dkx.com/arch/139.html
Non-special instructions are original articles such as reprint, please note: reprint from 5d happy blog [http://www.5DKX.com/]