Reputation:
I am facing a problem in character display on frame like this picture. In this picture a red circle is draw and there are some characters written on it.
My code is working fine except characters display function. I don't know what coordinates i give in these functions like glRotatef
glTranslatef
glScalef
to display the character according to picture.
Here is Code:
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;
}
Upvotes: 2
Views: 1239
Reputation: 1588
First of all your question is not defined well.I am assuming you want to do like the first picture using your code.
In your code you are drawing both "D" and "E" at the same position and scaling the output.To achieve the final output you have to translate and rotate all the characters a bit. You can do by modifying the current print function a bit.
First change the scalef value of 1/152 to 1/552 inside print. Add a rotatef with an argument. Then call the print function with relevant position and rotation argument.For usage see opengl documentation of the functions.
Edit:
Here is my code:
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();
}
Upvotes: 1