I am learning Open GL and I want to be able to draw the image below, can anyone help in the code?

Asked

Viewed 193 times

0

My biggest difficulty is being able to represent several images in different positions on the screen

  • I would like to move the image by clicking a 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;
}

inserir a descrição da imagem aqui

  • What have you done so far? Edit the question and add your try.

  • You can see the answer I’ve provided, you have the code I’ve made.

  • Gabriel the field below is not for that. Read here: https://pt.meta.stackoverflow.com/a/5510/28595

  • Thank you @Articuno the code is no longer in the answer I added in the same question.

  • What purpose are you learning Opengl? College? What is your knowledge of programming? Beginner, basic. You have experience with C language?

  • It was for college, I have knowledge in JAVA programming, it was first time working with C but I noticed that there is not much difference.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.