Low levels of pre-training with OpenGL

I have a noticeably low level of performance with my OpenGL project, sometimes slow enough to cause the application to crash. It works at about 1 frame per second, but I would prefer 20, or, if possible, I would like 60. So my program does whether a bitmap is needed, takes red, green and blue from one of the pixels, saves one and the same color pixel in the HDC, resets coordinates, etc., until it finishes all the pixels and prints it on the screen.

Here is my code:

#include "bitmap_image.h"
#include <windows.h>
#include <gl/gl.h>
#include <iostream>
using namespace std;
HDC Image(HDC hDC, string File_Name, int x_position, int y_position, int length, int height)
{
File_Name = "C:/Users/David/Pictures/" + File_Name + ".bmp";    
bitmap_image image(File_Name);      // Open the bitmap
unsigned char red;
unsigned char green;
unsigned char blue;
restart:
image.get_pixel(x_position, y_position, red, green, blue);     // Get the red green and blue from x_position and y_position and     store it in red green and blue. 
glBegin (GL_TRIANGLES);                                        // Make a pixel at x_position and y_position with red green and blue.
glColor3ub (red, green, blue);
glVertex2f (-1 + 0.0015 * x_position, 1 - 0.003 * y_position);
glVertex2f (-1 + 0.0015 * x_position, 0.997 - 0.003 * y_position);
glVertex2f (-0.9985 + 0.0015 * x_position, 1 - 0.003 * y_position);
glEnd();
glBegin (GL_TRIANGLES);
glColor3ub (red, green, blue);
glVertex2f (-1 + 0.0015 * x_position, 0.997 - 0.003 * y_position);
glVertex2f (-0.9985 + 0.0015 * x_position, 1 - 0.003 * y_position);
glVertex2f (-0.9985 + 0.0015 * x_position, 0.997 - 0.003 * y_position);
glEnd();
if (x_position==length)      // If x_position equals to length of bmp set x_position to 0 and add 1 to y_position.
{
if (y_position==height)      // If bmp is done loading go to done.
{
goto done;
}
x_position = 0;
y_position = y_position + 1;
}
x_position = x_position + 1;
goto restart;
done:         
return hDC;           
}

void Load_Image(HDC hDC)
{
SwapBuffers(hDC);                                  // Load the image
}

int main()
{
int x = 0;                                                                                                    
int y = 500;
HDC River = Image(hDC, "River", 0, 0, 1340, 678);                // make the river
HDC Turtle_1 = Image(River, "Turtle", x, y, 95, 65);            // make the turtle 10 pixels away on the river
x = x + 10;                                                                                              // push the turtle 10 more pixels
HDC Turtle_2 = Image(River, "Turtle", x, y, 95, 65);            // make the turtle 20 pixels away on the river
x = x + 10;                                                                                              // and so on... 
HDC Turtle_3 = Image(River, "Turtle", x, y, 95, 65);
x = x + 10;
HDC Turtle_4 = Image(River, "Turtle", x, y, 95, 65);
x = x + 10;
HDC Turtle_5 = Image(River, "Turtle", x, y, 95, 65);
x = x + 10;
HDC Turtle_6 = Image(River, "Turtle", x, y, 95, 65);
x = x + 10;
HDC Turtle_7 = Image(River, "Turtle", x, y, 95, 65);
x = x + 10;
HDC Turtle_8 = Image(River, "Turtle", x, y, 95, 65);
x = x + 10;
HDC Turtle_9 = Image(River, "Turtle", x, y, 95, 65);
x = x + 10;
HDC Turtle_10 = Image(River, "Turtle", x, y, 95, 65);
x = x + 10;
HDC Turtle_11 = Image(River, "Turtle", x, y, 95, 65);
x = x + 10;
HDC Turtle_12 = Image(River, "Turtle", x, y, 95, 65);
x = x + 10;
HDC Turtle_13 = Image(River, "Turtle", x, y, 95, 65);
x = x + 10;
HDC Turtle_14 = Image(River, "Turtle", x, y, 95, 65);
x = x + 10;
HDC Turtle_15 = Image(River, "Turtle", x, y, 95, 65);
x = x + 10;
HDC Turtle_16 = Image(River, "Turtle", x, y, 95, 65);
x = x + 10;
HDC Turtle_17 = Image(River, "Turtle", x, y, 95, 65);
x = x + 10;
HDC Turtle_18 = Image(River, "Turtle", x, y, 95, 65);
x = x + 10;
HDC Turtle_19 = Image(River, "Turtle", x, y, 95, 65);
x = x + 10;
HDC Turtle_20 = Image(River, "Turtle", x, y, 95, 65);
Load_Image(Turtle_1);               // Load the images to make the video
Load_Image(Turtle_2);
Load_Image(Turtle_3);                                                               
Load_Image(Turtle_4);
Load_Image(Turtle_5);
Load_Image(Turtle_6);
Load_Image(Turtle_7);
Load_Image(Turtle_8);
Load_Image(Turtle_9);
Load_Image(Turtle_10);
Load_Image(Turtle_11);
Load_Image(Turtle_12);
Load_Image(Turtle_13);
Load_Image(Turtle_14);
Load_Image(Turtle_15);
Load_Image(Turtle_16);
Load_Image(Turtle_17);
Load_Image(Turtle_18);
Load_Image(Turtle_19);
Load_Image(Turtle_20);
}

Note # 1 about code: you can find bitmap_image.h at http://partow.net/programming/bitmap/

Note # 2 on code: I did not take into account OpenGL functions such as: EnableOpenGL, DisableOpenGL, etc.

- ? !

+4
2

glBegin(GL_TRIANGLE_STRIP) gl.

, ?

0

valarray() , gsplice() , fps , .

. 18 . ? , , ? 3 . 4, 5 ..

-1

Source: https://habr.com/ru/post/1612992/


All Articles