Opengl 使用GLC库在GLFW中呈现字体时的问题

Opengl 使用GLC库在GLFW中呈现字体时的问题,opengl,glfw,Opengl,Glfw,我正在使用glc库在glfw窗口的上下文中呈现字体。但是,我无法设置字体的坐标。它总是在(0,0)位置(即左下角)呈现字体 下面是使用GLC库呈现示例字符串的代码 int main(){ GLint ctx, myFont; if (!glfwInit()) exit(EXIT_FAILURE); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT

我正在使用glc库在glfw窗口的上下文中呈现字体。但是,我无法设置字体的坐标。它总是在(0,0)位置(即左下角)呈现字体

下面是使用GLC库呈现示例字符串的代码

int main(){
    GLint ctx, myFont;

    if (!glfwInit())
        exit(EXIT_FAILURE);

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
    GLFWwindow* window = glfwCreateWindow(500, 500, "font rendering", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }
    glfwMakeContextCurrent(window);
    glewExperimental = GL_TRUE;
    glfwSwapInterval(1);
    if ( GLEW_OK != glewInit( ) )
        {
        std::cout << "Failed to initialize GLEW" << std::endl;

        }


 ctx = glcGenContext();
 glcContext(ctx);
 myFont = glcGenFontID();
 glcNewFontFromFamily(myFont, "Palatino");
 glcFontFace(myFont, "Normal");
 glcFont(myFont);

 glViewport(0, 0, 500, 500);
 glMatrixMode(GL_PROJECTION); // make the projection matrix the current matrix
 glLoadIdentity();            // init the projection matrix by the identity matrix
 glOrtho(0.0, 500.0, 500.0, 0.0, -1.0, 1.0); // top-left (0, 0); bottom-right (500, 500)
  glcScale(100,100);
  glcRenderString("Sample Text");
 glMatrixMode(GL_MODELVIEW);  // make the modelview matrix the current matrix
 glLoadIdentity();            // init the modelview matrix by the identity matrix


glfwSwapBuffers(window);

while(!glfwWindowShouldClose(window)){

}
intmain(){
闪烁ctx,myFont;
如果(!glfwInit())
退出(退出失败);
glfwWindowHint(GLFW_上下文_版本_专业,3);
glfwWindowHint(GLFW_上下文_版本_次要,0);
GLFWwindow*window=glfwCreateWindow(500500,“字体呈现”,NULL,NULL);
如果(!窗口)
{
glfwTerminate();
退出(退出失败);
}
glfwMakeContextCurrent(窗口);
glewExperimental=GL_TRUE;
glfwSwapInterval(1);
if(GLEW_OK!=glewInit())
{

std::cout投影矩阵描述了对象如何投影到视口上。如果没有投影矩阵,则必须在标准化设备空间中设置对象,其中所有坐标都在[-1.0,1.0]范围内

由于您希望在二维中绘制,因此我建议设置正交投影,将视图空间1:1映射到窗口坐标。
用于此,并用于在投影矩阵堆栈和modelview矩阵堆栈之间切换:

glViewport(0, 0, 500, 500);

glMatrixMode(GL_PROJECTION); // make the projection matrix the current matrix
glLoadIdentity();            // init the projection matrix by the identity matrix
glOrtho(0.0, 500.0, 500.0, 0.0, -1.0, 1.0); // top-left (0, 0); bottom-right (500, 500)

glMatrixMode(GL_MODELVIEW);  // make the modelview matrix the current matrix
glLoadIdentity();            // init the modelview matrix by the identity matrix

glcScale(100,100);

.....

分别使用呈现字符串。因为位置必须由设置

如果要以红色呈现字符串,则必须跳过红色和绿色组件

e、 g


谢谢@rabbi76,我已经根据你的建议编辑了这个问题。根据
glOrtho
,文本应该在(0,0)处呈现例如,在左上角,但如前所述,它显示在左下角。在使用GLC渲染字体时,我无法使用“glColor”和“glTranslate”函数,GLC是否提供其他函数使字体着色?与“glTranslate”一样,我使用了“glRasterPos3f()”函数。
glPixelTransferf(GL_RED_SCALE, 1.0f);
glPixelTransferf(GL_GREE_SCALE, 0.0f); 
glPixelTransferf(GL_BLUE_SCALE, 0.0f);