簡體   English   中英

Visual Studio Express 2017 Output 不顯示筆划文本 function

[英]Visual Studio Express 2017 Output not displaying for stroke text function

我一直在嘗試在 visual studio express 2017 中運行這個程序。使用 opengl。我在 pdf 中找到了渲染代碼和筆畫代碼並嘗試了它但首先它顯示了很多錯誤,一旦處理好我編譯了程序。 雖然運行沒有任何錯誤,但 output 屏幕仍然空白。

#include "stdafx.h"
#include <windows.h>
#include <gl/GL.h>
#include <glut.h>
#include <gl/GLU.h>

void myInit(void)
{
    glClearColor(1.0, 1.0, 1.0, 0.0);
    glColor3f(0.0f, 0.0f, 0.0f);
    glMatrixMode(GL_PROJECTION);
    glLineWidth(6.0);
    glLoadIdentity();
    gluOrtho2D(0.0, 700, 0.0, 700);
}

void drawStrokeText(const char *string, int x, int y, int z)
{
    const char *c;
    glPushMatrix();
    glTranslatef(x, y + 8, z);
    glScalef(0.09f, -0.08f, z);
    for (c = string; *c != '\0'; c++)
    {
        glutStrokeCharacter(GLUT_STROKE_ROMAN, *c);
    }
    glPopMatrix();
}

void render()
{
    glClear(GL_COLOR_BUFFER_BIT);
    glLoadIdentity();
    glColor3ub(255, 50, 255);
    drawStrokeText("Hello", 300, 400, 0);
    glutSwapBuffers();
}

void myDisplay(void)
{
    glClear(GL_COLOR_BUFFER_BIT);
    render();
    glFlush();
}

int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    glutInitWindowSize(700, 700);
    glutInitWindowPosition(100, 150);
    glutCreateWindow("My First Program");
    glutDisplayFunc(myDisplay);
    myInit();
    glutMainLoop();
}

矩陣模式在myInit中切換到GL_PROJECTION ,但從未切換回來。 因此render中的glLoadIdentity()指令將覆蓋投影矩陣。 您必須在glLoadIdentity()之前將矩陣模式切換為GL_MODELVIEW

void render()
{
    glClear(GL_COLOR_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);     // <--
    glLoadIdentity();
    glColor3ub(255, 50, 255);
    drawStrokeText("Hello", 300, 400, 0);
    glutSwapBuffers();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM