打开gl静态图 [英] open gl static drawing

查看:104
本文介绍了打开gl静态图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有c ++的opengl开发类似Paint的应用程序.但是每次我用鼠标绘制一个对象时,先前的图像或对象都会丢失.我该如何解决这个问题,请帮忙!

i am developing a paint like application using opengl with c++. But everytime i draw an object using mouse the previous image or object is lost. how can i solve this please help!

推荐答案

这是默认行为,应保持这种方式.您需要为每个屏幕重新绘制完整的模型".这意味着,当用户绘制一条线时,而不是立即绘制一条线,您应该将其属性保留在内存中(连同之前绘制的所有线条)并触发屏幕刷新(在OpenGL中,您很可能会有一个主循环,以特定速率刷新屏幕).
据我所知,每次openGL绘制一个框架时,它都会剔除上一次出现的内容.
This is the default behaviour and should be kept this way. You need to redraw your full "model" for each screen. This means that when the user draws a line, instead of immediately drawing, you should keep its properties in memories (along with all previous lines drawn) and trigger a refresh of the screen (in OpenGL, you would most probably have a main loop that refreshes the screen at a specific rate).
In your draw function, you would then need to redraw all your elements.


因此,每个帧都需要指定每个对象+摄像机+灯光的位置/变换.

为了显示多个对象,您将需要一种存储有关此对象的信息的方式,该信息可在绘制时使用.

因此,每次使用鼠标创建对象时,请保存绘制对象所需的所有信息,并将此信息添加到场景中所有对象的列表(由您创建和维护)中.

然后,当需要绘制场景时,只需逐步浏览已创建对象的列表,即可随心所欲地变换和绘制每个对象.



简单的openGlut伪代码可能类似于:

myDrawFunc
向量pos1,pos2

glLoadIdentity
glTranslatef(pos1)
-完成绘制object1的步骤
..
..
..


glLoadIdentity
glTranslatef(pos2)
完成绘制object2的步骤
..
..
..


我只是对此很陌生,本周初我第一次在openGL上尝试过.但这就是我(想想!!)对我的理解.
干杯. :)
From what I understand, each time openGL draws a frame, it culls whatever was there last time. So each frame you need to specify the location/transformation of each object + camera + lights.

In order to display more than 1 object, you''ll need a way of storing information about this object that can be used when drawing it.

So, each time you create an object with the mouse, save all the information needed to draw it & add this information to a list(that you create and maintain) of all objects in the scene.

Then when it comes time to draw the scene, just step through the list of created objects, transforming & drawing each one as you go.



simple openGlut pseudocode may resemble:

myDrawFunc
vector pos1, pos2

glLoadIdentity
glTranslatef(pos1)
-- do the steps to draw object1
..
..
..


glLoadIdentity
glTranslatef(pos2)
do the steps to draw object2
..
..
..


I''m only _very_ new to this, having first tried my hand at openGL earlier this week. But this is the understanding that I (think?!) I have.
Cheers. :)


这篇关于打开gl静态图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆