Я реализую алгоритм Брезенхэма, и я почти уверен, что моя реализация правильная, но экран по-прежнему пустой, я думаю, что неправильно использую OpenGL.
Это моя полная программа. Я использую nupengl.core.0.1.0.1, если это помогает
#include <GL\glew.h>
#include <GL\freeglut.h>
#include <iostream>
#include <fstream>
#include <math.h>
#define Round(a) (int)(a+0.5)
#define max(a,b) (a>b)?a:b
using namespace std;
/*truct vectors = {
vector
}*/
void init(void) {
glClearColor(1.0, 0.0, 0.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 200.0, 0.0, 150.0);
}
class Shape {
public:
virtual void Draw() = 0;
};
class lineBressenham : public Shape {
int x1, y1, x2, y2;
public:
lineBressenham(int a1, int b1, int a2, int b2) {
x1 = a1;
y1 = b1;
x2 = a2;
y2 = b2;
}
void Draw() {
int dx = x2 - x1;
int dy = y2 - y1;
int x = x1;
int y = y1;
int p = 2 * dy - dx;
glBegin(GL_POINTS);
while (x < x2) {
if (p >= 0) {
glVertex2i(x, y);
y = y + 1;
p = p + 2 * dy - 2 * dx;
}
else {
glVertex2i(x, y);
p = p + 2 * dy;
}
x = x + 1;
}
glEnd();
}
};
void displayWindow(void) {
ifstream infile;
glClear(GL_COLOR_BUFFER_BIT); // settings for buffer.
glColor3f(0.0, 0.0, 0.0);
glPointSize(3.0);
while (!infile.eof()) {
int a;
int x1 = 3, y1 = 4, x2 = 7, y2 = 9;
Shape* shape;
shape = new lineBressenham(x1, y1, x2, y2);
shape->Draw();
glutSwapBuffers();
//glFlush(); // draw everything in input, buffer in one time.
}
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500, 500); // window size
glutInitWindowPosition(0, 0); // distance from the top-left screen
glutCreateWindow("Show the window"); // message displayed on top bar window
glewInit();
if (glewIsSupported("GL_VERSION_3_3")) {
std::cout << " GLEW Version is 3.3\n ";
}
else {
std::cout << "GLEW 3.3 not supported\n ";
}
glutDisplayFunc(displayWindow);
init();
glutMainLoop();
return 0;
}
infile
? Это не похоже на то, что вы открываете файл. - person genpfault   schedule 28.07.2020