如何繪製2D & OpenGL中的3D材質?如果可能,請給我看一些C++代碼。 請同時顯示如何在3D對象前面繪製&。如何在OpenGL中一起繪製2D和3D材質?
2
A
回答
6
關於這樣:
void render_perspective_scene(void);
void render_ortho_scene(void);
void render_HUD();
void display()
{
float const aspect = (float)win_width/(float)win_height;
glViewport(0,0,win_width,win_height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-aspect*near/lens, aspect*near/lens, -near/lens, near/lens, near, far);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
render_perspective_scene();
// just clear the depth buffer, so that everything that's
// drawn next will overlay the previously rendered scene.
glClear(GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-aspect*scale, aspect*scale, -scale, scale, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
render_ortho_scene();
// Same for the HUD, only that we render
// that one in pixel coordinates.
glClear(GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, win_width, 0, win_height, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
render_HUD();
}
5
你在正確的軌道上,但是您繪製2D圖形時,還必須禁用深度測試:glDisable(GL_DEPTH_TEST);
否則可能會被你的3D圖形變成隱藏。
+0
只有當我們在3D場景背後繪製東西時,diable depth test纔有意義? – jondinham
相關問題
- 1. 在同一個OpenGL窗口中繪製2D和3D
- 2. 如何在OpenGL中繪製3D矢量?
- 3. 在OpenGL中繪製3D場景中的2D文本(C++)
- 4. Opengl在3D場景上繪製2D覆蓋圖問題
- 5. 使用Gnuplot在3d圖中繪製一組2d的繪圖
- 6. 繪製2D七邊形OpenGL
- 7. 繪製3D使用OpenGL
- 8. Java openGL - 繪製3D對象
- 9. 如何在R中的3D圖中繪製多個2d圖?
- 10. 在Android(和iOS)上使用Qt繪製3D效果與openGL的2D效果
- 11. 同時繪製一個2D位圖和一個3D模型
- 12. 如何在OpenGL ES 2.0中將紋理繪製爲2D背景?
- 13. 如何在OpenGL中繪製2D不規則曲線形狀
- 14. 如何在OpenGL中繪製3D環形圖?
- 15. OpenGL:在2D場景中以2D方式繪製文本?
- 16. 如何在OpenGL中設置金屬材質(如銀色)?
- 17. 在opengl中繪製一個島的2D輪廓
- 18. Java3d:如何在Java 3D場景上繪製2d覆蓋圖?
- 19. 如何在Java 3D場景上繪製2D覆蓋圖?
- 20. 用3D + 2D圖形重新繪製QGLWidget
- 21. 在jmonkeyengine中爲OGre 3D模型啓用材質和紋理?
- 22. 用於OpenGL中的2D和3D圖形操作的單一API
- 23. 如何在iPhone上繪製3D模型輪廓? (OpenGL ES)
- 24. 在立方體表面/牆體上繪製2d線統一3D
- 25. 在統一3D立方體上繪製2D線
- 26. Minko:如何在3D加載模型上應用材質(紋理)
- 27. 如何在XNA中繪製2D像素?
- 28. 如何在R中繪製3D箭頭?
- 29. 如何在MATLAB中繪製3D角度
- 30. Matlab:如何在3D中繪製文本
我試過gluPerspective畫事情3D,然後用glOrtho畫的東西在2D,但隨後3D的東西似乎覆蓋所有的二維圖紙,從而使這些2D東西閃爍! – jondinham
任何解決方案?.. – jondinham
請提供您現有的代碼,我們需要查看您所嘗試的內容,以便我們可以進一步幫助您。 –