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();
}
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();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.