剪裁区域
In OpenGL when you create a window to draw in we must specify the coordinate system we want to use and how to map the specified coordinates into physical screen coordinates. We would be using the 2D Cartesian coordinate system with the origin 0,0 at the centre of the screen. Before we can start plotting points, lines and shapes in a window we must also specify how to translate coordinate pairs into screen coordinates, by specifying the clipping area i.e the region of Cartesian space that occupies the window.
视口
The clipping area height and width will rarely match the width and height of the window in pixels. The coordinate system must therefore be mapped from logical Cartesian coordinates to physical screen coordinates. This mapping is specified by a setting known as the viewport, which is the region within the window's client area that is used for drawing the clipping area.
顶点和基本图元
A vertex is nothing more than a coordinate in 2D or 3D space. In both 2D and 3D, when we draw an object we compose it with several smaller shapes called primitives which as 1 or 2 dimensional entities such as points, lines, and polygons. Each corner of an object composed of primitives is a vertex
基本图形绘制程序
1,在CCY457OpenGLView.h中加入下列变量:
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->BOOLm_bPoint;//StatusofPoint
BOOLm_bLine;//StatusofLine
BOOLm_bPolygon;//StatusofPolygon
BOOLm_bTriangle;//StatusofTriangle
2,并且加入四个菜单项及其对应的事件处理程序。
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->voidCCY457OpenGLView::OnShapesPoint()
{//画点
m_bPoint=TRUE;
m_bLine=FALSE;
m_bPolygon=FALSE;
m_bTriangle=FALSE;
InvalidateRect(NULL,FALSE);
}
voidCCY457OpenGLView::OnShapesLine()
{//画线
m_bPoint=FALSE;
m_bLine=TRUE;
m_bPolygon=FALSE;
m_bTriangle=FALSE;
InvalidateRect(NULL,FALSE);
}
voidCCY457OpenGLView::OnShapesPolygon()
{//画多边形
m_bPoint=FALSE;
m_bLine=FALSE;
m_bPolygon=TRUE;
m_bTriangle=FALSE;
InvalidateRect(NULL,FALSE);
}
voidCCY457OpenGLView::OnShapesTriangle()
{//画三角形
m_bPoint=FALSE;
m_bLine=FALSE;
m_bPolygon=FALSE;
m_bTriangle=TRUE;
InvalidateRect(NULL,FALSE);
}
3,修改第二篇文章中的OnSize()函数,因为本文中只绘制2维图形.
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->voidCCY457OpenGLView::OnSize(UINTnType,intcx,intcy)
{
CView::OnSize(nType,cx,cy);
GLdoubleaspect_ratio;//width/heightratio
if(0>=cx||0>=cy)
{
return;
}
//selectthefullclientarea
::glViewport(0,0,cx,cy);
//computetheaspectratio
//thiswillkeepalldimensionscalesequal
aspect_ratio=(GLdouble)cx/(GLdouble)cy;
//selecttheprojectionmatrixandclearit
::glMatrixMode(GL_PROJECTION);
::glLoadIdentity();
//selecttheviewingvolume
//::gluPerspective(45.0f,aspect_ratio,.01f,200.0f);
::gluOrtho2D(-10.0f,10.0f,-10.0f,10.0f);
//switchbacktothemodelviewmatrixandclearit
::glMatrixMode(GL_MODELVIEW);
::glLoadIdentity();
}
4,在RenderScene中加入具体的绘制代码:
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->voidCCY457OpenGLView::RenderScene()
{//绘制函数
if(m_bPoint==TRUE)
{
glPointSize(3.0f);
glBegin(GL_POINTS);
glVertex2f(0.0f,0.0f);
glVertex2f(1.0f,0.0f);
glVertex2f(0.0f,1.0f);
glEnd();
}
elseif(m_bLine==TRUE)
{
glBegin(GL_LINES);
glVertex2f(0.0f,0.0f);
glVertex2f(1.0f,0.0f);
glEnd();
}
elseif(m_bTriangle==TRUE)
{
glBegin(GL_TRIANGLES);
glVertex2f(0.0f,0.0f);
glVertex2f(2.0f,0.0f);
glVertex2f(0.0f,2.0f);
glEnd();
}
elseif(m_bPolygon==TRUE)
{
glBegin(GL_POLYGON);
glVertex2f(0.0f,0.0f);
glVertex2f(3.0f,0.0f);
glVertex2f(4.0f,3.0f);
glVertex2f(1.5f,6.0f);
glVertex2f(-1.0f,3.0f);
glEnd();
}
}
分享到:
相关推荐
Partial symmetry detection for 2D shapes
Shapes 是一款实时向量图库,带有高质量的线条画和无限分辨率的图形,并以高级的抗锯齿技术渲染 功能特色 高质量的线条画,带有随机厚度以及高级抗锯齿 • 可指定厚度单位为米、像素或节点 • 2D 形状,比如多段线、...
Learn advanced graphical techniques including 2D lighting, rendering textured polygons, and drawing 3D primitive shapes Use third party libraries for data, networking, and more Gain a deep ...
Shapes2D是Unity资产,用于在Unity编辑器中轻松创建艺术资产。 您可以使用Shapes2D创建PNG精灵,原型设计,游戏卡纸,UI,效果等等。 您可以获取Shapes2D,或克隆此存储库,然后将Assets / Shapes2D复制到项目的...
3. OpenGL 4. The One With Shapes 5. The Cube 6. The Solar System 7. The One With The Mouse 8. The One That Rotates 9. The Rainbow Cube 10. The Golden Sphere 11. The Treasure Box 12. The One With ...
OPENGL is a visual component, which provides a simple user interface for drawing simple OPENGL. User can draw nodes (vertices) on the control s client area and link them together (graph s edges or ...
Shapes is a real-time vector graphics library with high-quality line drawing and infinite resolution shapes, rendered with advanced anti-aliasing techniques
基于openGL的图形学相关性研究Numerical Geometry of Non-Rigid Shapes
这考虑了一种新颖的,基于熵的形状复杂度度量,该度量在模型复杂度和模型近似误差之间取得了平衡。 为了最小化AIC标准,提出了两种变体并进行了评估:(a)从单个开始逐渐增加所考虑的椭圆数的增广法(AEFA),以及...
A method for registration of 3-D shapes,提出ICP算法的的第一篇论文
These fun examples are modeled after popular App Store games and teach you key concepts of the newcocos2d 2game engine and relevant tools like TexturePacker (texture atlas), PhysicsEditor (physics ...
Example 3: 3d Text using OpenGL routines Example 4: Rotating box and pyramid showing frame counter Example 5: Particle engine and billboard demonstration Example 6: Rotating cube using ...
简单形状 试图创建矩形,圆形等形状以使用它进行简单的游戏,这是它的测试平台。
Unity插件Shapes最新版 4.2.1
This is a sample of drawing 3D shapes in opengl!
PD IEC TR 62595-1-3:2019 Display lighting unit Part 1-3:Lighting units with arbitrary shapes -完整英文版(21页).pdf
icp经典文献,第一篇提出icp算法的论文,该论文使用四元数的方法介绍了icp算法
Alien3d是一款体积非常之小的Android 3D游戏引擎,基于OpenGL ES技术开发。为了压缩体积,它根据不同功能采用多jar方式发布(包括alien3d-engine.jar,alien3d- tiled.jar,alien3d-sprites.jar,alien3d-shapes.jar...
Shapes2
【视频教程】Hands-on Three.js 3D Web Visualisations-September 16, 2019.part3.rar Hands-on Three.js 3D Web Visualisations September 16, 2019 English | MP4 | AVC 1920×1080 | AAC 48KHz 2ch | 3h 46m | ...