Glut字符显示功能问题opengl
Glut characters display function issue opengl
我在像这张照片这样的框架上遇到字符显示问题。图中画了一个红圈,上面写了一些字
除了字符显示功能,我的代码工作正常。我不知道我在glRotatef
glTranslatef
glScalef
这些功能中给出什么坐标来根据图片显示字符。
代码如下:
using namespace std;
float x = 1, y = 1;
void init(void) {
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
void drawCircle(float pointX, float pointY, float Radius, int PointsDrawn)
{
glBegin(GL_TRIANGLE_FAN);
for (int i = 0; i < PointsDrawn; i++)
{
float theta = i * (2.0f * (float)M_PI / PointsDrawn);
float x = Radius * cos(theta);
float y = Radius * sin(theta);
glVertex2f(x + pointX, y + pointY);
}
glEnd();
}
void print(float x, float y, char* text)
{
glPushMatrix();
glScalef(5,5,2);
glTranslatef(x, y, 0);
glutStrokeCharacter(GLUT_STROKE_ROMAN, *text);
glPopMatrix();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f,0.0f,0.0f);
drawCircle(0.0f, 0.0f, 0.80f, 360);
glColor3f(1.0f,1.0f,1.0f);
print(-0.5f, 0.5f, "D");
glFlush();
}
void reshapeFunc(int width, int height) {
if (height == 0) {
height = 1;
}
else {
height = height;
}
float aspectRatio = (GLfloat)width / (GLfloat)height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (width <= height)
glOrtho(-x, x, -y / aspectRatio, y / aspectRatio, -1.0, 1.0);
else
glOrtho(-x*aspectRatio, x*aspectRatio, -y, y, -1.0, 1.0);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitWindowSize(590, 590);
glutInitWindowPosition(50, 50);
glutCreateWindow("Frame");
init();
glutDisplayFunc(&display);
glutReshapeFunc(&reshapeFunc);
glutMainLoop();
return EXIT_SUCCESS;
}
首先你的问题没有定义well.I我假设你想用你的代码像第一张图片那样做。
在您的代码中,您在同一位置绘制 "D" 和 "E" 并缩放 output.To 以实现最终输出,您必须稍微平移和旋转所有字符.您可以通过稍微修改当前的打印功能来实现。
先把print里面1/152的scalef值改成1/552。添加一个带有参数的 rotatef。然后使用相关位置和旋转调用打印函数 argument.For 用法请参阅函数的 opengl 文档。
编辑:
这是我的代码:
void print(float x, float y, float z,char* text) {
glPushMatrix();
glTranslatef(x, y, 0);
glScalef(1/552.0,1/552.0,1);
glRotatef(z,0,0,1);
glutStrokeCharacter(GLUT_STROKE_ROMAN, *text);
glPopMatrix();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f,0.0f,0.0f);
drawCircle(0.0f, 0.0f, 0.80f, 360);
glColor3f(1.0f,1.0f,1.0f);
char *ch="DEVELOP";
for (int i = 0; i <7; ++i)
{
float rad=M_PI/180;
double ang=135-15*i;
double ang_letter=45-15*i;
print(0.6*cos(ang*rad), 0.6*sin(ang*rad),ang_letter,ch+i);
}
glFlush();
}
我在像这张照片这样的框架上遇到字符显示问题。图中画了一个红圈,上面写了一些字
除了字符显示功能,我的代码工作正常。我不知道我在glRotatef
glTranslatef
glScalef
这些功能中给出什么坐标来根据图片显示字符。
代码如下:
using namespace std;
float x = 1, y = 1;
void init(void) {
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
void drawCircle(float pointX, float pointY, float Radius, int PointsDrawn)
{
glBegin(GL_TRIANGLE_FAN);
for (int i = 0; i < PointsDrawn; i++)
{
float theta = i * (2.0f * (float)M_PI / PointsDrawn);
float x = Radius * cos(theta);
float y = Radius * sin(theta);
glVertex2f(x + pointX, y + pointY);
}
glEnd();
}
void print(float x, float y, char* text)
{
glPushMatrix();
glScalef(5,5,2);
glTranslatef(x, y, 0);
glutStrokeCharacter(GLUT_STROKE_ROMAN, *text);
glPopMatrix();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f,0.0f,0.0f);
drawCircle(0.0f, 0.0f, 0.80f, 360);
glColor3f(1.0f,1.0f,1.0f);
print(-0.5f, 0.5f, "D");
glFlush();
}
void reshapeFunc(int width, int height) {
if (height == 0) {
height = 1;
}
else {
height = height;
}
float aspectRatio = (GLfloat)width / (GLfloat)height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (width <= height)
glOrtho(-x, x, -y / aspectRatio, y / aspectRatio, -1.0, 1.0);
else
glOrtho(-x*aspectRatio, x*aspectRatio, -y, y, -1.0, 1.0);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitWindowSize(590, 590);
glutInitWindowPosition(50, 50);
glutCreateWindow("Frame");
init();
glutDisplayFunc(&display);
glutReshapeFunc(&reshapeFunc);
glutMainLoop();
return EXIT_SUCCESS;
}
首先你的问题没有定义well.I我假设你想用你的代码像第一张图片那样做。
在您的代码中,您在同一位置绘制 "D" 和 "E" 并缩放 output.To 以实现最终输出,您必须稍微平移和旋转所有字符.您可以通过稍微修改当前的打印功能来实现。
先把print里面1/152的scalef值改成1/552。添加一个带有参数的 rotatef。然后使用相关位置和旋转调用打印函数 argument.For 用法请参阅函数的 opengl 文档。
编辑:
这是我的代码:
void print(float x, float y, float z,char* text) {
glPushMatrix();
glTranslatef(x, y, 0);
glScalef(1/552.0,1/552.0,1);
glRotatef(z,0,0,1);
glutStrokeCharacter(GLUT_STROKE_ROMAN, *text);
glPopMatrix();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f,0.0f,0.0f);
drawCircle(0.0f, 0.0f, 0.80f, 360);
glColor3f(1.0f,1.0f,1.0f);
char *ch="DEVELOP";
for (int i = 0; i <7; ++i)
{
float rad=M_PI/180;
double ang=135-15*i;
double ang_letter=45-15*i;
print(0.6*cos(ang*rad), 0.6*sin(ang*rad),ang_letter,ch+i);
}
glFlush();
}