问题描述
|
我想在游戏区域附近渲染轮廓字体,但是这两个部分存在冲突。如果我仅渲染轮廓字体,那就可以了。当我渲染游戏区域时,立方体的纹理也有缺陷,并且光线也会改变。当我仅渲染游戏区域时,就可以了。这是一些图片:
http://img.obrazok.com/Untitled.usdh.png
轮廓字体部分:
//Display-lists
GLuint fontBase;
GLYPHMETRICSFLOAT gmf[256];
//********************************
//3D Font
//********************************
GLvoid BuildFont(GLvoid) // Build Our Bitmap Font
{
HFONT font; // Windows Font ID
fontBase = glGenLists(256); // Storage For 256 Characters
font = CreateFont( -12,// Height Of Font
0,// Width Of Font
0,// Angle Of Escapement
0,// Orientation Angle
FW_BOLD,// Font Weight
FALSE,// Italic
FALSE,// Underline
FALSE,// Strikeout
ANSI_CHARSET,// Character Set Identifier
OUT_TT_PRECIS,// Output Precision
CLIP_DEFAULT_PRECIS,// Clipping Precision
ANTIALIASED_QUALITY,// Output Quality
FF_DONTCARE|DEFAULT_PITCH,// Family And Pitch
\"Comic Sans MS\"); // Font Name
HDC hDC = GetDC(GetActiveWindow());
SelectObject(hDC,font); // Selects The Font We Created
wglUseFontOutlines( hDC,// Select The Current DC
0,// Starting Character
255,// Number Of Display Lists To Build
fontBase,// Starting Display Lists
0.0f,// Deviation From The True Outlines
0.2f,// Font Thickness In The Z Direction
WGL_FONT_POLYGONS,// Use Polygons,Not Lines
gmf); // Address Of Buffer To Recieve Data
}
GLvoid KillFont(GLvoid) // Delete The Font
{
glDeleteLists(fontBase,256); // Delete All 256 Characters
}
void printString(const char *string,float x,float y,float z) // Custom GL \"Print\" Routine
{
float length=0; // Used To Find The Length Of The Text
for (unsigned int loop=0;loop<(strlen(string));loop++) // Loop To Find Text Length
{
length+=gmf[string[loop]].gmfCellIncX; // Increase Length By Each Characters Width
}
glPushMatrix();
glRotatef(90,0.0,1.0);
glRotatef(90,1.0,0.0);
glTranslatef(x,y,z);
glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits
glListBase(fontBase); // Sets The Base Character to 0
glCallLists(strlen(string),GL_UNSIGNED_BYTE,string); // Draws The Display List Text
glPopAttrib(); // Pops The Display List Bits
glPopMatrix();
}
渲染游戏区:
//Display-lists
GLuint ls_mapWalls;
void renderWalls() {
for (int x = 0; x < mapSize; x++) {
for (int y = 0; y < mapSize; y++) {
glPushMatrix();
glTranslatef(x*2.0f,y*2.0f,0.0f);
if (map[x][y] == \'X\') {
renderWall();
}
glPopMatrix();
}
}
}
void renderWall() {
glPushMatrix();
renderTexturedCube(1); //1 or 2
glPopMatrix();
}
void renderTexturedCube(int color) {
glEnable(GL_TEXTURE_2D);
switch (color) {
case 1 :
//normal wall
setMaterialColor(1.0f,1.0f,0.2f);
break;
case 2 :
//red wall
setMaterialColor(1.0f,0.0f,1.0f);
break;
}
glBindTexture(GL_TEXTURE_2D,texid[0]);
glBegin(GL_QUADS);
// Front Face
glNormal3f(0.0,1.0);
glTexCoord2f(0.0f,0.0f); glVertex3f(-1.0f,-1.0f,1.0f);
glTexCoord2f(1.0f,0.0f); glVertex3f( 1.0f,1.0f); glVertex3f( 1.0f,1.0f);
glTexCoord2f(0.0f,1.0f); glVertex3f(-1.0f,1.0f);
// Back Face
glNormal3f(0.0,-1.0);
glTexCoord2f(1.0f,-1.0f);
glTexCoord2f(1.0f,-1.0f);
glTexCoord2f(0.0f,-1.0f);
// Top Face
glNormal3f(0.0,0.0);
glTexCoord2f(0.0f,-1.0f);
// Bottom Face
glNormal3f(0.0,-1.0,0.0);
glTexCoord2f(1.0f,1.0f);
// Right face
glNormal3f(1.0,0.0);
glTexCoord2f(1.0f,1.0f);
// Left Face
glNormal3f(-1.0,0.0);
glTexCoord2f(0.0f,-1.0f);
glEnd();
setMaterialColor(1.0f,1.0f);
glDisable(GL_TEXTURE_2D);
}
渲染部分:
void render(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
GLdouble ex = vzd*cos(fi)*cos(xi);
GLdouble ey = vzd*sin(fi)*cos(xi);
GLdouble ez = vzd*sin(xi);
gluLookAt( ex,ey,ez,1.0f );
printString(\"Dyna Blaster Beta\",10,0.0);
glCallList(ls_mapWalls);
glutSwapBuffers();
}
初始化部分:
bool init(void)
{
//setup OpenGL
glShadeModel(GL_SMOOTH);
glClearColor(0.0f,0.5f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
glClearColor (0.0,0.0);
glEnable(GL_CULL_FACE);
//files load
loadMap();
loadTextures();
//next init
ls_mapWalls = glGenLists(1);
glNewList(ls_mapWalls,GL_COMPILE);
renderWalls();
glEndList();
glLightf(GL_LIGHT0,GL_CONSTANT_ATTENUATION,2.0);
GLfloat light_ambient[] = { 0.1,0.1,1.0 };
GLfloat light_diffuse[] = { 1.0,1.0 };
GLfloat light_specular[] = { 1.0,1.0 };
GLfloat light_position[] = { 10.0,10.0,0.0 };
glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient);
glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse);
glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular);
glLightfv(GL_LIGHT0,GL_POSITION,light_position);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
BuildFont();
fi = 0.385f; xi = 0.515f; vzd = 69.2f;
return true;
}
如果您有任何疑问或想要查看代码的另一部分,请询问。谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)