Visual Studio Express 2017输出未显示中风文本功能

发布于 2025-01-23 06:27:20 字数 1328 浏览 3 评论 0原文

我一直在尝试在Visual Studio Express 2017中运行此程序。使用OpenGL。 我在PDF中找到了渲染代码和中风代码,并正在尝试,但首先显示出许多错误,一旦照顾我,我都编制了该程序。尽管运行没有任何错误,但输出屏幕仍然空白。

#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();
}

I've been trying to run this program in visual studio express 2017. Using opengl.
I found the rendering code and stroke code in a pdf and was trying it out but first it showed many errors, once taken care of I compiled the program. Although the run was without any errors the output screen remains blank.

#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();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

別甾虛僞 2025-01-30 06:27:20

矩阵模式在myinit中切换到gl_proctive,但从未切换。因此,glloadIdentity() 中的指令将覆盖投影矩阵。您必须将矩阵模式切换到gl_modelview glloadIdentity()

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

Matrix mode is switched to GL_PROJECTION in myInit but never switched back. Therefore the glLoadIdentity() instruction in render will override the projection matrix. You have to switch the matrix mode to GL_MODELVIEW before glLoadIdentity():

void render()
{
    glClear(GL_COLOR_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);     // <--
    glLoadIdentity();
    glColor3ub(255, 50, 255);
    drawStrokeText("Hello", 300, 400, 0);
    glutSwapBuffers();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文