目录结构:
extern/glew
/glut
src/nvglutils/nvShaderUtils.h // dependent on glew
/nvwidgets/nvGlutWidgets.cpp, nvGlutWidgets.h // dependent on glut
/nvwidgets/nvGLWidgets.cpp, nvGLWidgets.h // dependent on opengl
/nvwidgets/nvWidgets.cpp, nvWidgets.h
/examples/example.cpp
类结构:
nvWidgets.h, class UIPainter and class UIContext.
GLWidgets.h, class GLUIPainter: public UIPainter {
//implement all the virtual functions of the base class,
//to draw ui elements with OpenGL.
GLUIPainter();
begin(const Rect &window);
end();
drawXXXX(...);
...
init();//compile and like shaders. invoked by begin(...) function.
};
class UIContext {
//This class is ready for use, but use the GlutUIContext as adaptor.
UIContext( UIPainter& painter ); // use painter(GLUIPainter) to draw UI.
reshape(int w, int h);
isOnFocus();
mouse(int button, int state, ...);
keyboard(unsigned char k, int x, int y);
begin(); //m_painter->begin(m_window);
end(); //m_painter->end();
doLabel(...);// use the painter to drawLabel;
doButton(...);// use the painter to drawButton;
...
UIPainter *m_painter;
Rect m_window;
Point m_currentCursor;
ButtonState m_mouseButton[3];
unsigned char m_keyBuffer[32];
....
};
GlutWidgets.h, class GlutUIContext: public UIContext {
// As an adaptor for GLUT,
GlutUIContext():UIContext(*(new GLUIPainter())), m_ownPainter(true) {}
GlutUIContext(UIPainter &painter):UIContext(painter), m_ownPainter(false) {}
init(); // invoke glewInit();
mouse(int button, int state, int x, int y); //translate the Glut mouse to nvWidgets mouse.
specialKeyboard(int k, int x, int y);
};
小结:
(1)一个负责底层draw UI的类UIPainter,用OpenGL做底层API的话就实现一个GLUIPainter,如果用DirectX做渲染的话就实现一个DXUIPainter.
这个类被UIContext调用。
(2)一个负责管理窗口的UIContext类,工作包括记录自己的windows(大小位置等),响应keyboard/mouse的输入,对用UIPainter来画UI.
提供了GlutUIContex作为adapter,是否也可以实现Win32UIContext, QtUIContext.
(3)这个nvwidgets目的只是在glut提供的窗口上用OpenGL来画出UI和相应这些UI,
like the author of this project said, it is suitable for small dome.
假如是在Win32上实现,不知是否类似。
假如是在Qt上实现,Qt好像是提供class QPainter to render 2D widgets.
(4)另外,貌似提供的example占用99%CPU.
原来可能是:
static void idle()
{
glutPostRedisplay();
}
glutIdleFunc(idle);
When the application is idle(not responding to event), it refresh constantly(also often used to implement animation).
Email from the author:
That's expected. nvwidgets processes the input and draws the screen
simultaneously. It was designed for real-time applications that are
constantly redrawing the screen, so in those cases that was not an
issue.
This however is one of the main complains people have; there's an
issue already open about it:
http://code.google.com/p/nvidia-widgets/issues/detail?id=1
the IMGUI forums also discuss this issue and propose solutions:
https://mollyrocket.com/forums/viewforum.php?f=10
A simple workaround is not to refresh the screen constantly, but limit
it to 60 or 30 Hz. That can be achieved with WaitableTimers. See the
comment section of the following article:
http://cbloomrants.blogspot.com/2009/03/03-02-09-sleep-sucks-and-vsync-woes.html
另外涉及的link including:
http://meshula.net/wordpress/?p=189
http://www.gamedev.net/community/forums/topic.asp?topic_id=445787&whichpage=2?
问题包括:
(4.1) 游戏shot CPU usage to 100%是否合适? 意见包括对于real-time application来说,this 's not an issue. 反面意见是, the computer's fans roar like a vacuum cleaner. Power consumption. Expecially for a loptop.
(4.2) 如果不想要100%usage, then not to refresh the screen constantly, but limit it to a framerate 60 or 30 Hz. But how? using timer, 方法一般是:
Use a timer to record the time at which you started rendering the current frame. Add 1/120th of a second to that, and you know when the next frame should start.
Once you've finished rendering the current frame, you take the current time, and check how far it is from the "next frame" time we computed.
Then you call Sleep(int) with the time difference.
同样地在上面提到的cbloomrants.blogspot.com那个link中有伪代码.
但是好像windows上的Sleep() is a huge disaster, it's not exact.
(5) What is IMGUI?
https://mollyrocket.com/forums/viewforum.php?f=10
http://sol.gfxile.net/imgui/
http://sol.gfxile.net/files/Assembly07_IMGUI.pdf
没有评论:
发表评论