我主要需要2D方面的,如果有3D的也可以,谢谢啦!
解决方案 »
- directshow缓冲模式获取视频数据的一个问题,急求解!!!
- mfc 开发office 的工具栏 activex 控件时,需要继承那些接口,及步骤?
- 关于QQ程序的CPU占用率的问题
- 为什么主窗口标题一开始运行的时候始终都不显示?
- 高手请进,函数运行完后,弹出对话框,提示该程序遇到问题,需要关闭
- 求助:在对话框内打开PowerPoint的方法?
- 以前的关于全局变量的贴子,现开新贴,请大虾们继续支持。
- 关于jmail编写邮件程序的一个问题,请高手指教!(100分相送)
- 老谭也盗版?
- MFC编写的串口通信程序,接收不到数据???
- NT系统服务程序的问题,高手请进!(在线100)
- 如果发现有人正通过Modem拨号,如何用程序实现将拨号断开,高分求教!!100分
向大家推荐:《vc从入门到精通》中的MiniDraw非常不错,适合各种做图形开发软件环境的朋友参考。
所以,你可以看到3D游戏中为什么都是很简单的地形,棱角突出的人物,就是因为过多的顶点极大的影响了游戏的速度
CWnd::InvalidateRect
void InvalidateRect( LPCRECT lpRect, BOOL bErase = TRUE );ParameterslpRectPoints to a CRect object or a RECT structure that contains the rectangle (in client coordinates) to be added to the update region. If lpRect is NULL, the entire client area is added to the region.bEraseSpecifies whether the background within the update region is to be erased.ResInvalidates the client area within the given rectangle by adding that rectangle to the CWnd update region. The invalidated rectangle, along with all other areas in the update region, is ed for painting when the next WM_PAINT message is sent. The invalidated areas accumulate in the update region until the region is processed when the next WM_PAINT call occurs, or until the region is validated by the ValidateRect or ValidateRgn member function.The bErase parameter specifies whether the background within the update area is to be erased when the update region is processed. If bErase is TRUE, the background is erased when the BeginPaint member function is called; if bErase is FALSE, the background remains unchanged. If bErase is TRUE for any part of the update region, the background in the entire region is erased, not just in the given part. Windows sends a WM_PAINT message whenever the CWnd update region is not empty and there are no other messages in the application queue for that window.CWnd Overview | Class Members | Hierarchy ChartSee Also CWnd::BeginPaint, CWnd::ValidateRect, CWnd::ValidateRgn,::InvalidateRect
我没用过,你试试吧。
opengl是基于双缓冲的,一般不能只绘制部分,前后缓冲一交换,以前画的东西就统统消灭光了(如果你上一次画了一个茶壶,而这一次不画,茶壶就没了,不象gdi,只要不在茶壶上画新的东西,茶壶就一直存在),哪里还容你只重绘一部分,部分重绘只有你的显卡支持才可以(通过扩展机制支持),常规的opengl都是一刷新就统统刷新了
opengl中要想快速绘制,首先是要避免实时运算,还有就是尽量减少要绘制的顶点的个数,尽量采用显示列表
2。在OpenGL很耗时的是渲染,建议把同类的东西一起绘出后在描绘另外一类的东西,例如空间中有许多红球和蓝球,最好是把他们分类绘制,这样虽然分类化了时间和精力,但对于速度的提高还是非常值得的。
3。对于在视见空间中的对象要进行位置判断,界外的东西不要进行任何绘制操作,对于比较远的东西,可以用降低精度或者直接用点代替。
4。如果有可能,自己写函数代替标准函数来进行基本图元的绘制,标准函数为了结果的正确而牺牲了速度,自己写的函数却可以缩小适用范围而提高速度。
5。用贴图来代替大面积渲染的颜色块。
6。适当使用显示列表。
7。为了提高速度,牺牲程序的封装性也在所不惜,因为没有任何一个慢速的三维程序是好程序。好了,就写这么多,自己多研究一下程序结构和算法吧。
如果需要重绘的话,你肯定有许多OpenGL图形,将这些图形按照object组织起来,如下:CTypedPtrArray<CObArray,CGLModel*> m_GLModelArray;
m_GLModelArray的定义是本课题设计中的核心之一,它解决了所有动态生成的原子模型的组织问题,同时也解决了原子模型的重画问题、存储问题。m_GLModelArray管理一组CGLModel(原子模型基类)派生的对象,而CGLModel和它所派生的对象都有自己的Serialize成员函数,系统通过调用读写m_GLModelArray的Add()方法存放所有的原子模型对象。原子模型父对象示例:
class CGLModel:public CObject
{
public:
float m_Color[3]; //模型颜色
float m_RotateX; //X方向旋转参数
float m_RotateY; //Y方向旋转参数
float m_RotateZ; //Z方向旋转参数
float m_ScaleX; //X方向缩放参数
float m_ScaleY; //Y方向缩放参数
float m_ScaleZ; //Z方向缩放参数
UINT name; //模型的类名
CGLMaterial Material;//模型材质参数
CGLModel ():Material()//缺省构造函数,同时缺省构造Material成员对象
{
m_RotateX=0;//初始不旋转
m_RotateY=0;
m_RotateZ=0;
m_ScaleX=1;//初始不缩放
m_ScaleY=1;
m_ScaleZ=1;
}
DECLARE_SERIAL(CGLModel)
public:
virtual void SetColor(float r,float g,float b)//设置模型颜色
{
...}
virtual void Draw(){} //对没有被选中的模型进行
};
原子模型对象示例:
//*****球*****//
class CGLSphere:public CGLModel
{
protected:
float m_X,m_Y,m_Z; //球心
float m_Radius; //半径
CGLSphere () {} //构造
DECLARE_SERIAL(CGLSphere)
public:
CGLSphere(CGLSphere *pGLModel);
CGLSphere(float x,float y,float z,float radius);
virtual void Draw();
virtual void SelectedDraw();
void TextureDraw();
virtual void Move(float distanceX,float distanceY,float distanceZ);
virtual void Rotate(float Rx,float Ry,float Rz);
virtual void Serialize(CArchive &ar);
void Init();
};添加新的模型到m_GLModelArray:
CGLModel *pCGLModel;
pCGLModel=new CGLSphere((float)m_PointOrigin.x,(float)m_PointOrigin.y,0.0f,radius);
m_GLModelArray.Add(pGLModel);
如果上面清楚,那么在CGLSphere中加一函数boolean IsInRect(CRect rect)判断CGLSphere是否在需要重绘的区域内(使用CRect只判断二维平面),若在区域内则重绘.具体使用如下:
使用循环调用m_GLModelArray中每个模型的IsInRect,为true则调用其draw()重绘.CRect rect的可根据鼠标作图时的一个最大范围取得.
因为没有时间编程,楼主试试吧!