gpt4 book ai didi

c++ - 简单的 2D 应用程序,在使用 glutBitmapCharacter 时遇到问题

转载 作者:行者123 更新时间:2023-11-28 07:56:31 29 4
gpt4 key购买 nike

我想简单地在屏幕上写任何东西。绘制矩形很容易。我试图将文本字符串横向叠加在“书”上。看起来很简单,但是...

请注意,我尝试从这些论坛中获取建议,所以 glDisable(GL_DEPTH_TEST);glDisable(GL_LIGHTING);可能没有必要。另外,有没有办法自己调试?我通常喜欢添加 cout << "i reached this far yay" << endl;但是当我把它放在 void Bookshelf() 中时它似乎不喜欢我...它给了我一个 C2381 错误('function' : redefinition; __declspec(noreturn) differs)

主要.cpp

#include "bookshelf.h"

void Initialize()
{
glClearColor (1.0, 1.0, 1.0, 0.0 );
glMatrixMode( GL_PROJECTION );
glOrtho(0,899,899,0,1,0);
}
void main( int argc, char *argv[] )
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB );
glutInitWindowSize( 900, 900 );
glutInitWindowPosition( 510, 100 );
glutCreateWindow("Bookshelf - Ankit Ahuja");
Initialize();
glutDisplayFunc(Bookshelf);
glutMainLoop();
}

书架.h

#include <GL/glut.h>  

void Bookshelf()
{
glClear( GL_COLOR_BUFFER_BIT );
glColor3f( 0.0, 0.0, 0.0 );
glBegin( GL_QUADS );

//Code that draws a bookshelf
//Book1
glColor3f( 1.0, 0.25, 0.25 );
glVertex3i(240,70,0.5);
glVertex3i(260,70,0.5);
glVertex3i(260,180,0.5);
glVertex3i(240,180,0.5);

//BookTitle1
glPushMatrix();
glLoadIdentity();
glDisable(GL_DEPTH_TEST);
glRotatef(90f,0.0f,0.0f,0.0f);
glColor3f( 0.0, 1.0, 0.0 );
glDisable(GL_LIGHTING);
glRasterPos3i(100,100,1);

char text[50]="Alphabet Soup is the best guys";
for(int i=0; i<50; i++)
{
glutBitmapCharacter(GLUT_BITMAP_9_BY_15,(int)text[i]);
}
glPopMatrix();

//Book2
glColor3f( 0.8, 0.8, 0.0 );
glVertex2i(270,70);
glVertex2i(290,70);
glVertex2i(290,180);
glVertex2i(270,180);

//More books and shelves
glEnd();
glFlush();
}

最佳答案

在显示文本之前,您应该使用 glOrtho 设置正交投影。

确保你在写你的文本之前正确地推/弹出投影和模型 View 矩阵,这样你就会看到类似的东西:

glMatrixMode(GL_PROJECTION);    //Select projection matrix
glPushMatrix(); //save it
glLoadIdentity();

glMatrixMode(GL_MODELVIEW); //Select modelview matrix
glPushMatrix(); //save it
glLoadIdentity();

// set up ur glOrtho
glOrtho(...);

glutBitmapCharacter(...)

glMatrixMode(GL_PROJECTION);
glPopMatrix(); //Restore your old projection matrix

glMatrixMode(GL_MODELVIEW);
glPopMatrix(); //Restore old modelview matrix

关于c++ - 简单的 2D 应用程序,在使用 glutBitmapCharacter 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12591737/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com