将“光照”应用于 gl_Quad 中的特定复选框
Apply Lighting to specific checkboxes in gl_Quad
我想在这个棋盘格的白色和黑色盒子上应用不同的照明。到目前为止,我做了什么。
myDisplay 函数中的嵌套循环正在创建框。
GLfloat ambientColor[] = {0.2f, 0.2f, 0.2f, 1.0f}; //Color(0.2, 0.2, 0.2)
GLfloat lightColor0[] = {0.5f, 0.5f, 0.5f, 1.0f}; //Color (0.5, 0.5, 0.5)
GLfloat lightPos0[] = {4.0f, 0.0f, 8.0f, 1.0f}; //Positioned at (4, 0, 8)
GLfloat lightColor1[] = {0.5f, 0.2f, 0.2f, 1.0f}; //Color (0.5, 0.2, 0.2)
//Coming from the direction (-1, 0.5, 0.5)
GLfloat lightPos1[] = {-1.0f, 0.5f, 0.5f, 0.0f};
void myInit(void)
{
glClearColor (1,1,0,0);
glPointSize(10);
glLineWidth(10.0);
glColor3f(1,1,1);
gluOrtho2D(0,640,0,480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//gluPerspective(45,2,-2,2);
gluLookAt(100.0,200.0,200.0,//eyeposition
0.0,0.0,0.0,//ccenter
0.0,1.0,0.0);//up direction
}
void myDisplay(void)
{
int posx=10;
int posy=10;
int posWidth=60;
int posHeight=60;
bool whiteORBlack=true;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_LIGHTING);
glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
// glLightfv(GL_LIGHT1, GL_DIFFUSE, lightColor1);
// glLightfv(GL_LIGHT1, GL_POSITION, lightPos1);
for(int j=1;j<=8;j++)
{
for(int i=1;i<=8;i++)
{
if(whiteORBlack==true)
{
glBegin(GL_QUADS);
glColor3f(0,0,0);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor0);
glLightfv(GL_LIGHT0, GL_POSITION, lightPos0);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor0);
glLightfv(GL_LIGHT0, GL_POSITION, lightPos0);
glVertex2i(posx,posy);
glVertex2i(posx+posWidth,posy);
glVertex2i(posx+posWidth,posy+posHeight);
glVertex2i(posx,posy+posHeight);
whiteORBlack=false;
}
else if(whiteORBlack==false)
{
glBegin(GL_QUADS);
glColor3f(1,1,1);
glVertex2i(posx,posy);
glVertex2i(posx+posWidth,posy);
glVertex2i(posx+posWidth,posy+posHeight);
glVertex2i(posx,posy+posHeight);
whiteORBlack=true;
}
posx=posx+posWidth;
}
if(whiteORBlack==false)
{
whiteORBlack=true;
}
else
{
whiteORBlack=false;
}
posy=posy+posHeight;
posx=10;
}
//glPopMatrix();
//glutSwapBuffers();
glEnd();
glFlush();
}
void main(int argc,char ** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize (640,480);
glutInitWindowPosition(100,150);
glutCreateWindow("FINAL LAB");
myInit();
glutDisplayFunc(myDisplay);
//glEnable(GL_LIGHTING);
//glEnable(GL_LIGHT0);
//glLightfv(GL_LIGHT0,GL_AMBIENT,light0_ambient);
//glLightfv(GL_LIGHT0,GL_DIFFUSE,ligth0_diffuse);
//glEnable(GL_DEPTH_TEST);
//glEnable(GL_CULL_FACE);
//glEnable(GL_BLEND);
//glEnable(GL_LINE_SMOOTH);
//glLineWidth(2);
//glMatrixMode(GL_PROJECTION);
/*gluPerspective(40,1,1,10);
glMatrixMode(GL_MODELVIEW);
gluLookAt(0.0,0.0,5.0,0.0,0.0,0.0,0.0,1.0,0.0);*/
glutMainLoop();
}
我认为您必须将所有glLightfv
内容设置为lightColor1
等。
与其每次都交换这个,我可能会将照明设置为黑色,绘制所有黑色,然后将照明设置为白色,并绘制所有白色。
如果我错了,那么屏幕截图可能有助于更好地回答您。
相关文章:
- 根据变量使Qt UI中的复选框为已选中/未选中
- "动态创建的事件处理程序"复选框
- 有没有办法在取消选中复选框时隐藏按钮?
- 如何删除Qt设计器中自定义插件的QString属性的"translatable"复选框?
- 设置复选框选项C++
- 如何在所有者描述的 MFC CMenu 派生菜单中显示复选框?
- 如何在MFC对话框应用程序中默认将复选框设置为选中?
- 如何使复选框独占
- AccessObjectFromPoint 返回客户端对象而不是复选框
- Windows 32 API:2个复选框作为一个
- 如何在 QT3 中将复选框添加到 QFileDialog 窗口
- 在 QComboBox 中切换复选框
- 调整QT创建者的复选框
- 如何在C 上创建复选框过滤器
- 如何设置按钮的背景颜色,包括复选框按钮
- 使用 ffh.getFieldType() 检查复选框 == "/Btn" 与 qpdf lib
- 如何在多行文本C++的左上角显示复选框
- Win32如何制作多个复选框并以不同的方式管理它们
- QtableWidget 标题上的复选框
- 如何使用QListView项目添加复选框