本文的全部代码
见
http://www.linuxidc.com/Linux/2013-02/78954p6.htm
http://www.linuxidc.com/Linux/2013-02/78954p7.htm
http://www.linuxidc.com/Linux/2013-02/78954p8.htm
http://www.linuxidc.com/Linux/2013-02/78954p9.htm
http://www.linuxidc.com/Linux/2013-02/78954p10.htm
http://www.linuxidc.com/Linux/2013-02/78954p11.htm
http://www.linuxidc.com/Linux/2013-02/78954p12.htm
附glFrame.h代码:
#ifndef GLFRAME_H_INCLUDED
#define GLFRAME_H_INCLUDED
#include "global.h"
#include "font.h"
#include "Label.h"
#include "Button.h"
void glfPrint(GLboolean doubleBuffer);
void glfInit();
void glfProcessKeyboard(KeySym keysym);
void glfProcessMouseClick(int x,int y);
void glfprocessButtonPress();
void glfUpdate();
void glfReshape(int width,int height);
void glfDraw();
Label label;
Button button;
Button b_exit;
void glfPrint(GLboolean doubleBuffer)
{
if (doubleBuffer)
glXSwapBuffers(dpy, win);
else
glFlush();
}
void glfInit()
{
glViewport(0, 0, glf_WinWidth, glf_WinHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glf_left=0.0f;
glf_right=50.0f;
glf_bottom=0.0f;
glf_top=50.0f;
glf_near=-1.0f;
glf_far=1.0f;
glOrtho(glf_left,glf_right,glf_bottom,glf_top,glf_near,glf_far);
glMatrixMode(GL_MODELVIEW);
makeRasterFont();
label.isShow=GL_TRUE;
label.color[0]=1.0f;
label.color[1]=1.0f;
label.color[2]=0.0f;
label.color[3]=0.0f;
label.posx=15;
label.posy=40;
strcpy(label.str,"HELLO SSSOGS");
button.isShow=GL_TRUE;
button.isAround=GL_TRUE;
button.aroundLineWidth=3;
button.aroundColor[0]=0.0f;
button.aroundColor[1]=1.0f;
button.aroundColor[2]=0.0f;
button.aroundColor[3]=0.0f;
button.leftDown.p[0]=4;
button.leftDown.p[1]=20;
button.leftUp.p[0]=4;
button.leftUp.p[1]=30;
button.rightDown.p[0]=24;
button.rightDown.p[1]=20;
button.rightUp.p[0]=24;
button.rightUp.p[1]=30;
button.color[0]=0.9f;
button.color[1]=0.5f;
button.color[2]=0.9f;
button.color[3]=0.0f;
button.text.isShow=GL_TRUE;
button.text.color[0]=0.0f;
button.text.color[1]=0.0f;
button.text.color[2]=0.0f;
button.text.color[3]=0.0f;
button.text.posx=6;
button.text.posy=25;
strcpy(button.text.str,"HIDE WORDS");
strcpy(button.event,"Test");
b_exit.isShow=GL_TRUE;
b_exit.isAround=GL_TRUE;
b_exit.aroundLineWidth=3;
b_exit.aroundColor[0]=0.0f;
b_exit.aroundColor[1]=1.0f;
b_exit.aroundColor[2]=0.0f;
b_exit.aroundColor[3]=0.0f;
b_exit.leftDown.p[0]=26;
b_exit.leftDown.p[1]=20;
b_exit.leftUp.p[0]=26;
b_exit.leftUp.p[1]=30;
b_exit.rightDown.p[0]=46;
b_exit.rightDown.p[1]=20;
b_exit.rightUp.p[0]=46;
b_exit.rightUp.p[1]=30;
b_exit.color[0]=0.9f;
b_exit.color[1]=0.5f;
b_exit.color[2]=0.9f;
b_exit.color[3]=0.0f;
b_exit.text.isShow=GL_TRUE;
b_exit.text.color[0]=0.0f;
b_exit.text.color[1]=0.0f;
b_exit.text.color[2]=0.0f;
b_exit.text.color[3]=0.0f;
b_exit.text.posx=28;
b_exit.text.posy=25;
strcpy(b_exit.text.str,"EXIT");
strcpy(b_exit.event,"exit");
}
void glfProcessKeyboard(KeySym keysym)
{
if (keysym == (KeySym)XK_Escape)
exit(0);
}
void glfProcessMousePress(int x,int y)
{
if (glfCheckButtonPress(x,y,button) == GL_TRUE)
{
glfprocessButtonPress();
}
if (glfCheckButtonPress(x,y,b_exit) == GL_TRUE)
{
glfprocessButtonPress();
}
}
void glfprocessButtonPress()
{
if (glf_buttonevent == NULL)
return ;
if (strcmp(glf_buttonevent,"Test") == 0)
{
label.isShow=!label.isShow;
if (label.isShow)
{
strcpy(button.text.str,"HIDE WORDS");
}
else
{
strcpy(button.text.str,"SHOW WORDS");
}
}
if (strcmp(glf_buttonevent,"exit") == 0)
{
exit(0);
}
}
void glfUpdate()
{
}
void glfReshape(int width,int height)
{
glf_WinWidth=width;
glf_WinHeight=height;
glViewport(0,0,glf_WinWidth,glf_WinHeight);
}
void glfDraw()
{
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
glfDrawLabel(label);
glfDrawButton(button);
glfDrawButton(b_exit);
glfPrint(glf_DoubleBuffer);
}
#endif // GLFRAME_H_INCLUDED
