I want to make this code run, but I'm still too much of a n00b on C, and OpenGL and VS 2008 to identify on which of them is the fault:
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
#include<math.h>
void init(void)
{
//set display-window background color to white
glClearColor(1.0,1.0,1.0,0.0);
//set projection paramaters
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0,300.0,0.0,300.0);
}
void setPixel(GLint xCoordinate, GLint yCoordinate)
{
glBegin(GL_POINTS);
glVertex2i(xCoordinate,yCoordinate);
glEnd();
glFlush(); //executes all OpenGL functions as quickly as possible
}
//Bresenham line-drawing procedure for |m| < 1.0
void lineBres(GLint x0, GLint y0, GLint xEnd, GLint yEnd)
{
GLint dx = fabs(xEnd - x0);
GLint dy = fabs(yEnd - y0);
GLint p = 2 * dy - dx;
GLint twoDy = 2 * dy;
GLint twoDyMinusDx = 2 * (dy-dx);
GLint x,y;
// determine which endpoint to use as start position
if (x0 > xEnd){
x = xEnd;
y = yEnd;
xEnd = x;
}else{
x = x0;
y = y0;
}
setPixel(x,y);
while(x<xEnd){
x++;
if(p<0)
p += twoDy;
else{
y++;
p += twoDyMinusDx;
}
setPixel(x,y);
}
}
void drawMyLine(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glPointSize(4.0);
GLint x0 = 100;
GLint y0 = 150;
GLint xEnd = 200;
GLint yEnd = 200;
lineBres(x0,y0,xEnd,yEnd);
}
void main(int argc, char*argv[])
{
//initialize GLUT
glutInit(&argc,argv);
//initialize display mode
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
//set display-window width & height
glutInitWindowSize(400,400);
//set display-window upper-left position
glutInitWindowPosition(0,0);
//create display-window with a title
glutCreateWindow("Digital Differential Analyzer Algorithm: Programmed by Salha");
//initialze OpenGL
init();
//call graphics to be displayed on the window
glutDisplayFunc(drawMyLine);
//display everything and wait
glutMainLoop();
}
Error messages:
1>------ Build started: Project: test2, Configuration: Debug Win32 ------
1>Compiling...
1>testing.c
1>e:\documents and settings\administrator\my documents\visual studio 2008\projects\test2\test2\testing.c(68) : error C2275: 'GLint' : illegal use of this type as an expression
1> e:\program files\microsoft sdks\windows\v6.0a\include\gl\gl.h(48) : see declaration of 'GLint'
1>e:\documents and settings\administrator\my documents\visual studio 2008\projects\test2\test2\testing.c(68) : error C2146: syntax error : missing ';' before identifier 'x0'
1>e:\documents and settings\administrator\my documents\visual studio 2008\projects\test2\test2\testing.c(68) : error C2065: 'x0' : undeclared identifier
1>e:\documents and settings\administrator\my documents\visual studio 2008\projects\test2\test2\testing.c(69) : error C2275: 'GLint' : illegal use of this type as an expression
1> e:\program files\microsoft sdks\windows\v6.0a\include\gl\gl.h(48) : see declaration of 'GLint'
1>e:\documents and settings\administrator\my documents\visual studio 2008\projects\test2\test2\testing.c(69) : error C2146: syntax error : missing ';' before identifier 'y0'
1>e:\documents and settings\administrator\my documents\visual studio 2008\projects\test2\test2\testing.c(69) : warning C4047: '=' : 'double (__cdecl *)(double)' differs in levels of indirection from 'int'
1>e:\documents and settings\administrator\my documents\visual studio 2008\projects\test2\test2\testing.c(69) : error C2106: '=' : left operand must be l-value
1>e:\documents and settings\administrator\my documents\visual studio 2008\projects\test2\test2\testing.c(69) : warning C4550: expression evaluates to a function which is missing an argument list
1>e:\documents and settings\administrator\my documents\visual studio 2008\projects\test2\test2\testing.c(70) : error C2275: 'GLint' : illegal use of this type as an expression
1> e:\program files\microsoft sdks\windows\v6.0a\include\gl\gl.h(48) : see declaration of 'GLint'
1>e:\documents and settings\administrator\my documents\visual studio 2008\projects\test2\test2\testing.c(70) : error C2146: syntax error : missing ';' before identifier 'xEnd'
1>e:\documents and settings\administrator\my documents\visual studio 2008\projects\test2\test2\testing.c(70) : error C2065: 'xEnd' : undeclared identifier
1>e:\documents and settings\administrator\my documents\visual studio 2008\projects\test2\test2\testing.c(71) : error C2275: 'GLint' : illegal use of this type as an expression
1> e:\program files\microsoft sdks\windows\v6.0a\include\gl\gl.h(48) : see declaration of 'GLint'
1>e:\documents and settings\administrator\my documents\visual studio 2008\projects\test2\test2\testing.c(71) : error C2146: syntax error : missing ';' before identifier 'yEnd'
1>e:\documents and settings\administrator\my documents\visual studio 2008\projects\test2\test2\testing.c(71) : error C2065: 'yEnd' : undeclared identifier
1>e:\documents and settings\administrator\my documents\visual studio 2008\projects\test2\test2\testing.c(72) : error C2065: 'x0' : undeclared identifier
1>e:\documents and settings\administrator\my documents\visual studio 2008\projects\test2\test2\testing.c(72) : warning C4047: 'function' : 'GLint' differs in levels of indirection from 'double (__cdecl *)(double)'
1>e:\documents and settings\administrator\my documents\visual studio 2008\projects\test2\test2\testing.c(72) : warning C4024: 'lineBres' : different types for formal and actual parameter 2
1>e:\documents and settings\administrator\my documents\visual studio 2008\projects\test2\test2\testing.c(72) : error C2065: 'xEnd' : undeclared identifier
1>e:\documents and settings\administrator\my documents\visual studio 2008\projects\test2\test2\testing.c(72) : error C2065: 'yEnd' : undeclared identifier
1>Build log was saved at "file://e:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\test2\test2\Debug\BuildLog.htm"
1>test2 - 15 error(s), 4 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========