openGL 选择和反馈(csGL)
2013-08-12 17:23
309 查看
画图形,定义模式为GL_SELECT,并为图形创建名字堆栈:
鼠标左键点击选中目标hit select:
/// <summary> /// Draws the rectangles. /// </summary> /// <param name="mode">The selection mode.</param> private static void DrawRects(uint mode) { // The three rectangles are drawn. In selection mode, each rectangle is given // the same name. Note that each rectangle is drawn with a different z value. if (mode == GL_SELECT) { glLoadName(1); } glBegin(GL_QUADS); glColor3f(1.0f, 1.0f, 0.0f); glVertex3i(2, 0, 0); glVertex3i(2, 6, 0); glVertex3i(6, 6, 0); glVertex3i(6, 0, 0); glEnd(); if (mode == GL_SELECT) { glLoadName(2); } glBegin(GL_QUADS); glColor3f(0.0f, 1.0f, 1.0f); glVertex3i(3, 2, -1); glVertex3i(3, 8, -1); glVertex3i(8, 8, -1); glVertex3i(8, 2, -1); glEnd(); if (mode == GL_SELECT) { glLoadName(3); } glBegin(GL_QUADS); glColor3f(1.0f, 0.0f, 1.0f); glVertex3i(0, 2, -2); glVertex3i(0, 7, -2); glVertex3i(5, 7, -2); glVertex3i(5, 2, -2); glEnd(); }
鼠标左键点击选中目标hit select:
/// <summary> /// Updates pick selection. /// </summary> private static void PickRects() { private const int BUFSIZE = 512; // sets up selection mode, name stack, and projection matrix for picking. Then the objects are drawn uint[] selectBuf = new uint[BUFSIZE]; int hits; int[] viewport = new int[4]; glGetIntegerv(GL_VIEWPORT, viewport); glSelectBuffer(BUFSIZE, selectBuf); glRenderMode(GL_SELECT); glInitNames(); glPushName(0); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); // create 5x5 pixel picking region near cursor location gluPickMatrix((double)Model.Mouse.X, (double)(viewport[3] - Model.Mouse.Y), 5.0, 5.0, viewport); glOrtho(0.0f, 8.0f, 0.0f, 8.0f, -0.5f, 2.5f); DrawRects(GL_SELECT); glPopMatrix(); glFlush(); hits = glRenderMode(GL_RENDER); ProcessHits(hits, selectBuf); } /// <summary> /// Displays hit data. /// </summary> /// <param name="hits">Number of hits.</param> /// <param name="buffer">The selection buffer.</param> private static void ProcessHits(int hits, uint[] buffer) { uint i, j; uint names; uint[] ptr; Console.WriteLine("hits = {0}", hits); ptr = buffer; for (i = 0; i < hits; i++) { // For Each Hit names = ptr[i]; Console.WriteLine(" number of names for hit = {0}", names); i++; Console.WriteLine(" z1 is {0}", (float)ptr[i] / 0x7fffffff); i++; Console.WriteLine(" z2 is {0}", (float)ptr[i] / 0x7fffffff); i++; Console.Write(" the name is "); for (j = 0; j < names; j++) { // For Each Name Console.Write("{0} ", ptr[i]); i++; } Console.Write("\n"); } Console.Write("\n"); }
相关文章推荐
- OpenGL 反馈选择模式
- 29. OpenGL--选择和反馈
- 选择与反馈 (OpenGL)
- 选择与反馈 (OpenGL)
- OpenGL--选择和反馈
- 选择与反馈 (OpenGL)
- OpenGL中的选择和反馈(转)
- OpenGL选择与反馈机制(转)
- OpenGL--选择和反馈
- OpenGL 射线选择中射线的生成过程,代码与图示参考
- .NET(C#) 中使用 CsGL-OpenGL .NET
- OpenGL-选择与拾取
- opengl环境下的射线选择
- OpenGL-反馈
- CSGL(OpenGL C#)下的文字输出
- OGL选择和反馈模式
- (译)LearnOpenGL实际案例Breakout(七):碰撞反馈
- 自己来做个简陋的OpenGL选择教程....
- 【OpenGL4.0】GLSL-使用Subroutines选择着色器功能
- OpenGL 选择机制(拾取)的理解和特别注意问题