I'm learning Open GL and I want to be able to draw the image below, can anyone help with the code?

0

My greatest difficulty is being able to represent multiple images at different positions on the screen

  • I would like to move the image by clicking any button on the keyboard.

I currently have the following code:

#include <windows.h>  // For MS Windows
#include <GL/glut.h>  // GLUT, includes glu.h and gl.h

/* Handler for window-repaint event. Call back when the window first appears and
   whenever the window needs to be re-painted. */
void display() {
   glClearColor(0.0, 0.0, 0.0, 1.0); // Set background color to black and opaque
   glClear(GL_COLOR_BUFFER_BIT);         // Clear the color buffer
   // Draw a Red 1x1 Square centered at origin
   glBegin(GL_TRIANGLES);              // Each set of 4 vertices form a quad
      glColor3f(1.0, 0.0, 0.0); // Red
      glVertex2f(-0.4, -0.1);    // x, y
      glVertex2f( 0.5, -0.1);
      glVertex2f( 0.0,  0.5);
   glEnd();

    glBegin(GL_QUADS);              // Each set of 4 vertices form a quad
      glColor3f(0.0, 1.0, 0.0); // Red
      glVertex2f(0.07, 0.4);    // x, y
      glVertex2f( -0.07, 0.4);
      glVertex2f( -0.07, -1.0);
      glVertex2f( 0.07, -1.0);
   glEnd();
glBegin(GL_QUAD_STRIP);              // Each set of 4 vertices form a quad
      glColor3f(0.0, 1.0, 1.0); // Red
      glVertex2f(-0.07, 0.6);    // x, y
      glVertex2f( -0.07, 0.4);
      glVertex2f( 0.2, 0.6);
      glVertex2f( 0.2, 0.4);
   glEnd();

    glBegin(GL_POLYGON);              // Each set of 4 vertices form a quad
      glColor3f(0.0, 1.0, 0.0); // Red
      glVertex2f(-1.0, -0.8);    // x, y
      glVertex2f( -0.5, -1.2);
      glVertex2f( 1.0, -0.8);
      glVertex2f( 0.5, -1.2);
   glEnd();

   glFlush();  // Render now
}


/* Main function: GLUT runs as a console application starting at main()  */
int main(int argc, char** argv) {
   glutInit(&argc, argv);                 // Initialize GLUT
   glutCreateWindow("OpenGL Setup Test"); // Create a window with the given title
    glutInitWindowPosition(200,50);   //200 Lelt 50 Height
    glutInitWindowSize(500,500);
   glutDisplayFunc(display); // Register display callback handler for window re-paint
   glutMainLoop();           // Enter the infinitely event-processing loop
   return 0;
}

    
asked by anonymous 10.06.2018 / 22:19

0 answers