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);
unsigned char red;
unsigned char green;
unsigned char blue;
restart:
image.get_pixel(x_position, y_position, red, green, blue);
glBegin (GL_TRIANGLES);
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 (y_position==height)
{
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);
}
int main()
{
int x = 0;
int y = 500;
HDC River = Image(hDC, "River", 0, 0, 1340, 678);
HDC Turtle_1 = Image(River, "Turtle", x, y, 95, 65);
x = x + 10;
HDC Turtle_2 = Image(River, "Turtle", x, y, 95, 65);
x = x + 10;
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_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.
- ? !