Skip to main content
deleted 519 characters in body; edited tags; edited title
Source Link
meteors
  • 165
  • 2
  • 8

OpenGL reshape and fontsresize problems

I'm developing a minesweeper game. I'm having two issues onea problem with reshaping and other with drawing numbers(resize) the window. I'm using Ubuntu Linux. Following are the code snippets and the entire code is here:

This is my initializing code that I write at the starting of main()

glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (400, 300);
glutCreateWindow ("MineSweeper");
glClearColor (1.0, 1.0, 1.0, 0.0);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);

This is my display() func that I pass into glutDisplayFunc() which actually draws the grid requires for minesweeper game.

glClear (GL_COLOR_BUFFER_BIT);

glColor3f (0.0, 0.0, 0.0);
glLineWidth (3);

float i;
for(i = step; i< 1; i+=step) {
    glBegin(GL_LINES);
        glVertex3f(i,0,0);
        glVertex3f(i,1.0,0);
    glEnd();
    glBegin(GL_LINES);
        glVertex3f(0,i,0);
        glVertex3f(1.0,i,0);
    glEnd();
}

glFlush ();

I searched many forum and finally tried this code for reshape() function in the glutReshapeFunc()

void reshape (int width, int height) {
   glViewport(0, 0, width, height);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(0, width, 0, height, -1.0, 1.0);
   glFlush();
}

But it didn't work and the output was a plane window.

Also I want to display numbers in a font style almost as shown below in different colors: Numbers

I've seen the bitmap fonts but they don't suffice my needs. Also is it better to use fonts or to draw them by hand using OpenGL functions or to import and draw images in OpenGL and if yes how do I import images such that they don't get distorted on resizing of window. I donot want the exact fonts as in the image but something similar would do.

OpenGL reshape and fonts problems

I'm developing a minesweeper game. I'm having two issues one with reshaping and other with drawing numbers. I'm using Ubuntu Linux. Following are the code snippets and the entire code is here:

This is my initializing code that I write at the starting of main()

glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (400, 300);
glutCreateWindow ("MineSweeper");
glClearColor (1.0, 1.0, 1.0, 0.0);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);

This is my display() func that I pass into glutDisplayFunc() which actually draws the grid requires for minesweeper game.

glClear (GL_COLOR_BUFFER_BIT);

glColor3f (0.0, 0.0, 0.0);
glLineWidth (3);

float i;
for(i = step; i< 1; i+=step) {
    glBegin(GL_LINES);
        glVertex3f(i,0,0);
        glVertex3f(i,1.0,0);
    glEnd();
    glBegin(GL_LINES);
        glVertex3f(0,i,0);
        glVertex3f(1.0,i,0);
    glEnd();
}

glFlush ();

I searched many forum and finally tried this code for reshape() function in the glutReshapeFunc()

void reshape (int width, int height) {
   glViewport(0, 0, width, height);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(0, width, 0, height, -1.0, 1.0);
   glFlush();
}

But it didn't work and the output was a plane window.

Also I want to display numbers in a font style almost as shown below in different colors: Numbers

I've seen the bitmap fonts but they don't suffice my needs. Also is it better to use fonts or to draw them by hand using OpenGL functions or to import and draw images in OpenGL and if yes how do I import images such that they don't get distorted on resizing of window. I donot want the exact fonts as in the image but something similar would do.

OpenGL resize problems

I'm developing a minesweeper game. I'm having a problem with reshaping(resize) the window. I'm using Ubuntu Linux. Following are the code snippets and the entire code is here:

This is my initializing code that I write at the starting of main()

glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (400, 300);
glutCreateWindow ("MineSweeper");
glClearColor (1.0, 1.0, 1.0, 0.0);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);

This is my display() func that I pass into glutDisplayFunc() which actually draws the grid requires for minesweeper game.

glClear (GL_COLOR_BUFFER_BIT);

glColor3f (0.0, 0.0, 0.0);
glLineWidth (3);

float i;
for(i = step; i< 1; i+=step) {
    glBegin(GL_LINES);
        glVertex3f(i,0,0);
        glVertex3f(i,1.0,0);
    glEnd();
    glBegin(GL_LINES);
        glVertex3f(0,i,0);
        glVertex3f(1.0,i,0);
    glEnd();
}

glFlush ();

I searched many forum and finally tried this code for reshape() function in the glutReshapeFunc()

void reshape (int width, int height) {
   glViewport(0, 0, width, height);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(0, width, 0, height, -1.0, 1.0);
   glFlush();
}

But it didn't work and the output was a plane window.

Source Link
meteors
  • 165
  • 2
  • 8

OpenGL reshape and fonts problems

I'm developing a minesweeper game. I'm having two issues one with reshaping and other with drawing numbers. I'm using Ubuntu Linux. Following are the code snippets and the entire code is here:

This is my initializing code that I write at the starting of main()

glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (400, 300);
glutCreateWindow ("MineSweeper");
glClearColor (1.0, 1.0, 1.0, 0.0);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);

This is my display() func that I pass into glutDisplayFunc() which actually draws the grid requires for minesweeper game.

glClear (GL_COLOR_BUFFER_BIT);

glColor3f (0.0, 0.0, 0.0);
glLineWidth (3);

float i;
for(i = step; i< 1; i+=step) {
    glBegin(GL_LINES);
        glVertex3f(i,0,0);
        glVertex3f(i,1.0,0);
    glEnd();
    glBegin(GL_LINES);
        glVertex3f(0,i,0);
        glVertex3f(1.0,i,0);
    glEnd();
}

glFlush ();

I searched many forum and finally tried this code for reshape() function in the glutReshapeFunc()

void reshape (int width, int height) {
   glViewport(0, 0, width, height);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(0, width, 0, height, -1.0, 1.0);
   glFlush();
}

But it didn't work and the output was a plane window.

Also I want to display numbers in a font style almost as shown below in different colors: Numbers

I've seen the bitmap fonts but they don't suffice my needs. Also is it better to use fonts or to draw them by hand using OpenGL functions or to import and draw images in OpenGL and if yes how do I import images such that they don't get distorted on resizing of window. I donot want the exact fonts as in the image but something similar would do.