2024年4月1日发(作者:)

一个简单的OpenGL拾取例子【注】

OpenGL鼠标拾取的大致样子。唉,一个堂堂的

“医生”,竟然要做这些coding的体力活。真丢人啊!!

#include

#include

#include

void init()

{

glClearColor(0, 0, 0, 0);

}

void drawObjects(GLenum mode)

{

if (mode == GL_SELECT) glLoadName(1);

glColor3f(1, 0, 0);

glRectf(-0.5, -0.5, 1.0, 1.0);

if (mode == GL_SELECT) glLoadName(2);

glColor3f(0, 0, 1);

glRectf(-1.0, -1.0, 0.5, 0.5);

}

void display()

{

glClear(GL_COLOR_BUFFER_BIT);

drawObjects(GL_RENDER);

glFlush();

}

void processHits(GLint hits, GLuint buffer[])

{

unsigned int i, j;