Some thinking after class

Source: Internet
Author: User
Tags clear screen

1,gltranslatef ( -1.5f,0.0f,-6.0f); Is this the object being observed moving, or is it moving in the position of the viewpoint?

My understanding is that the latter (as if the camera were moving to capture the picture), the default object position is the center of the screen, moving the view to the left and pushing the view away so that the observed object can enter, trying to adjust the value of the z-coordinate, you can see the more z going inside, the smaller the object, the larger the object, This is similar to the camera adjustment focal length.

2. Use flat coloring (monotone coloring) to apply a fixed color to the geometric object. Use smoothcoloring (smooth shading) to mix the different colors of several vertices together to create a beautiful blend of colors. Be aware that the window resizes and is reactivated when it is blocked by another window to reset the shade Model.

int Copengldemoview::D rawglscene (glvoid)
{//here ' s Where We did all the Drawing
Glclear (Gl_color_buffer_bit |     Gl_depth_buffer_bit); Clear screen and Depth Buffer
Glloadidentity (); Reset the current Modelview Matrix
Gltranslatef (-1.5f, 0.0f,-6.0f); The object moves to the left 1.5, moves inward 6, is the same as moving the lens, lets the object enter the lens
Glbegin (Gl_triangles); Draw triangles
glcolor3f (1.0f, 0.0f, 0.0f);
glvertex3f (0.0f, 1.0f, 0.0f); Top vertex
glcolor3f (0.0f, 1.0f, 0.0f);
glvertex3f (-1.0f,-1.0f, 0.0f); Lower left
glcolor3f (0.0f, 0.0f, 1.0f);
glvertex3f (1.0f,-1.0f, 0.0f); Lower right
Glend (); Triangle Draw End
Glshademodel (Gl_flat);
Gltranslatef (3.0f, 0.0f, 0.0f);
Glbegin (gl_quads); Draw a square
glcolor3f (1.0f, 0.0f, 0.0f);
glvertex3f (-1.0f, 1.0f, 0.0f); Top left

GLCOLOR3F (1.0, 1.0f, 1.0f);
glvertex3f (-1.0f,-1.0f, 0.0f); Lower right

glcolor3f (0.0f, 0.0f, 1.0f);
glvertex3f (1.0f,-1.0f, 0.0f); Lower left

glcolor3f (0.0f, 1.0f, 0.0f);
glvertex3f (1.0f, 1.0f, 0.0f); Top Right
Glend (); Square Draw End
Glflush ();
return TRUE; Everything Went OK
}

void Copengldemoview::onactivateview (BOOL bactivate, CView * pactivateview, CView * pdeactiveview)
{
Todo:add your specialized code here and/or call the base class
INITGL (); Force request to restore OpenGL State when window is activated

Cview::onactivateview (Bactivate, Pactivateview, Pdeactiveview);
}


void Copengldemoview::onsize (UINT ntype, int cx, int cy)
{
Cview::onsize (Ntype, CX, CY);

Todo:add your message Handler code here
Glsizei Width,height;
width = cx;
height = cy;
if (height = 0)//Prevent A Divide by Zero by
{
Height = 1; Making Height Equal One
}

Glshademodel (Gl_smooth);
Glviewport (0, 0, width,height); Reset the current Viewport

Glmatrixmode (gl_projection); Select the projection Matrix
Glloadidentity (); Reset the projection Matrix
Calculate the Aspect Ratio of the Window
Gluperspective (45.0f, (glfloat) Width/(glfloat) height, 0.1f, 100.0f); Perspective projection
Glmatrixmode (Gl_modelview); Select the Modelview Matrix
Glloadidentity (); Reset the Modelview Matrix
}


BOOL COPENGLDEMOVIEW::INITGL (glvoid)//All Setup for OpenGL Goes here
{
Glshademodel (Gl_smooth); Enable Smooth Shading
Glclearcolor (0.0, 0.0, 0.0, 0.0); Black Background
Glcleardepth (1.0f); Depth Buffer Setup
Glenable (gl_depth_test); Enables Depth testing
Gldepthfunc (gl_lequal); The Type of Depth testing to do
Glhint (Gl_perspective_correction_hint, gl_nicest); Really nice perspective calculations
return TRUE; Initialization Went OK
}

3, if the following is the setting of color, what will be the color of the square?

Glshademodel (Gl_flat);
Gltranslatef (3.0f, 0.0f, 0.0f);
Glbegin (gl_quads); Draw a square
glcolor3f (1.0f, 0.0f, 0.0f);
glvertex3f (-1.0f, 1.0f, 0.0f); Top left

GLCOLOR3F (1.0, 1.0f, 1.0f);
glvertex3f (-1.0f,-1.0f, 0.0f); Lower right

glcolor3f (0.0f, 0.0f, 1.0f);
glvertex3f (1.0f,-1.0f, 0.0f); Lower left

glcolor3f (0.0f, 1.0f, 0.0f);
glvertex3f (1.0f, 1.0f, 0.0f); Top Right
Glend (); Square Draw End
Oh, the answer is: The color will be green, that is, the last vertex of the color as the standard, this is because Flat coloring (monotone coloring) is to the quadrilateral coated with a fixed color, and the last vertex of the color set, after the previous color settings covered.


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.