xin chào , mình mới học đồ họa máy tính muốn chạy thử chương trình nhưng lỗi này là sao ạ và cách khắc phục ạ
bt1.cpp
void midPoint(int X1, int X2, int Y1, int Y2)
{
// calculate dx & dy
int dx = X2 - X1;
int dy = Y2 - Y1;
if(dy<=dx){
int d = dy - (dx/2);
int x = X1,y = Y1;
draw_pixel(x,y);
while (x < X2)
{
x++;
if (d < 0)
d = d + dy;
else
{
d += (dy - dx);
y++;
}
draw_pixel(x,y);
}
}
else if(dx<dy)
{
int d = dx - (dy/2);
int x = X1, y = Y1;
draw_pixel(x,y);
while (y < Y2)
{
y++;
if (d < 0)
d = d + dx;
else
{
d += (dx - dy);
x++;
}
draw_pixel(x,y);
}
}
}
main.cpp
#include <GL/glut.h>
#include <gl/glut.h>
#include <stdio.h>
int x1, y1, x2, y2;
void myInit() {
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.0, 0.0, 0.0, 1.0);
glMatrixMode(GL_MODELVIEW);
gluOrtho2D(-30, 30, -30, 30);
}
void draw_pixel(int x, int y) {
glBegin(GL_POINTS);
glVertex2i(x, y);
glPointSize(100);
glEnd();
}
void draw(int x1, int x2, int y1, int y2) {
int dx, dy, i, p;
int incx, incy, c1, c2;
int x,y;
dx = x2-x1;
dy = y2-y1;
x = x1;
y = y1;
draw_pixel(0,0);
if (dx < 0) dx = -dx;
if (dy < 0) dy = -dy;
// xét x2 và x1
if (x2 < x1) incx = -1;
else incx = 1;
// xét y2 và y1
if (y2 < y1) incy = -1;
else incy = 1;
if (dx > dy) {
p = 2 * dy-dx;
c1 = 2*(dy-dx);
c2 = 2*dy;
for(i=0;i<=dx;i++) {
draw_pixel(x, y);
if (p >= 0) {
y += incy;
p += c1;
}
else p += c2;
x += incx;
}
} else {
p = 2*dx-dy;
c1 = 2*(dx-dy);
c2 = 2*dx;
// while(y<=y2) {
for(i=0;i<=dy;i++) {
draw_pixel(x, y);
if (p >= 0) {
x += incx;
p += c1;
}
else p += c2;
y += incy;
}
}
}
void myDisplay() {
draw(x1, x2, y1, y2);
glFlush();
}
main(int argc, char **argv) {
printf( "Enter (x1, y1, x2, y2)\n");
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(0, 0);
glutCreateWindow("Bresenham's Line Drawing");
myInit();
glutDisplayFunc(myDisplay);
glutMainLoop();
}
em dùng prototype nhưng vẫn lỗi ấy ạ
bt1.cpp
void midPoint(int X1, int X2, int Y1, int Y2)
void draw_pixel(int x, int y) // em dùng funtion prototype van loi a//
{
// calculate dx & dy
int dx = X2 - X1;
int dy = Y2 - Y1;
if(dy<=dx){
int d = dy - (dx/2);
int x = X1,y = Y1;
draw_pixel(x,y);
while (x < X2)
{
x++;
if (d < 0)
d = d + dy;
else
{
d += (dy - dx);
y++;
}
draw_pixel(x,y);
}
}
else if(dx<dy)
{
int d = dx - (dy/2);
int x = X1, y = Y1;
draw_pixel(x,y);
while (y < Y2)
{
y++;
if (d < 0)
d = d + dx;
else
{
d += (dx - dy);
x++;
}
draw_pixel(x,y);
}
}
}
main.cpp
#include <GL/glut.h>
#include <gl/glut.h>
#include <stdio.h>
int x1, y1, x2, y2;
void myInit() {
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.0, 0.0, 0.0, 1.0);
glMatrixMode(GL_MODELVIEW);
gluOrtho2D(-30, 30, -30, 30);
}
void draw_pixel(int x, int y) {
glBegin(GL_POINTS);
glVertex2i(x, y);
glPointSize(100);
glEnd();
}
void draw(int x1, int x2, int y1, int y2) {
int dx, dy, i, p;
int incx, incy, c1, c2;
int x,y;
dx = x2-x1;
dy = y2-y1;
x = x1;
y = y1;
draw_pixel(0,0);
if (dx < 0) dx = -dx;
if (dy < 0) dy = -dy;
// xét x2 và x1
if (x2 < x1) incx = -1;
else incx = 1;
// xét y2 và y1
if (y2 < y1) incy = -1;
else incy = 1;
if (dx > dy) {
p = 2 * dy-dx;
c1 = 2*(dy-dx);
c2 = 2*dy;
for(i=0;i<=dx;i++) {
draw_pixel(x, y);
if (p >= 0) {
y += incy;
p += c1;
}
else p += c2;
x += incx;
}
} else {
p = 2*dx-dy;
c1 = 2*(dx-dy);
c2 = 2*dx;
// while(y<=y2) {
for(i=0;i<=dy;i++) {
draw_pixel(x, y);
if (p >= 0) {
x += incx;
p += c1;
}
else p += c2;
y += incy;
}
}
}
void myDisplay() {
draw(x1, x2, y1, y2);
glFlush();
}
main(int argc, char **argv) {
printf( "Enter (x1, y1, x2, y2)\n");
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(0, 0);
glutCreateWindow("Bresenham's Line Drawing");
myInit();
glutDisplayFunc(myDisplay);
glutMainLoop();
}