Pregunta

Quiero hacer que la fuente de contorno esté cerca del área de juego, pero estas dos partes están en conflicto. Si solo rinde la fuente del contorno, está bien. Cuando también rinde el área de juego, las texturas de los cubos tienen defectos y la luz también cambia. Cuando presento solo el área de juego, está bien. Aquí hay algunas fotos:http://img.obrazok.com/untitled.usdh.png

Parte de la fuente de esquema:

 //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,0.0,1.0);
    glRotatef(90,1.0,0.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();

}

Render el área de juego:

//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, 1.0f, 0.2f);
        break;
    case 2 :
        //red wall
        setMaterialColor(1.0f, 0.0f, 0.0f, 1.0f);
        break;
    }

    glBindTexture(GL_TEXTURE_2D, texid[0]);
    glBegin(GL_QUADS);
    // Front Face
    glNormal3f(0.0,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,  1.0f);
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
    // Back Face
    glNormal3f(0.0,0.0,-1.0); 
    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
    glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
    glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
    // Top Face
    glNormal3f(0.0,1.0,0.0);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
    // Bottom Face
    glNormal3f(0.0,-1.0,0.0); 
    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
    glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
    glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
    // Right face
    glNormal3f(1.0,0.0,0.0);
    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
    glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
    glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
    // Left Face
    glNormal3f(-1.0,0.0,0.0); 
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
    glEnd();

    setMaterialColor(1.0f, 1.0f, 1.0f, 1.0f);
    glDisable(GL_TEXTURE_2D);
}

Render Parte:

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, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f );


    printString("Dyna Blaster Beta", 10, 10, 10, 1.0, 0.0, 0.0);
    glCallList(ls_mapWalls);

    glutSwapBuffers();
}

Parte inicial:

bool init(void)
{
    //setup OpenGL
    glShadeModel(GL_SMOOTH);                            
    glClearColor(0.0f, 0.0f, 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, 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, 0.1, 1.0 };
    GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
    GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
    GLfloat light_position[] = { 10.0, 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;
}

Si tiene alguna pregunta o desea ver otra parte del código, solo pregunte. Gracias.

¿Fue útil?

Solución

La documentación para WGluseFonToutLines en MSDN dice esto:

With WGL_FONT_POLYGONS, the created display lists call glFrontFace( GL_CW )
or glFrontFace( GL_CCW ); thus the current front-face value might be altered.

OpenGL DetfullS a GL_CCW; Entonces es probable que lo retrases con

glFrontFace( GL_CCW );

Después de dibujar el texto, su área de juego se presentará correctamente.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top