1

I'm new with OpenGl and I try to run this example (source):

#include<GL/glu.h>
#include<GL/glut.h>
#include<stdio.h>
#include<stdlib.h>

int xa,xb,ya,yb;
void display (void)
{
int dx=xb-xa;
int dy=yb-ya;
int p0 = 2*dy - dx;
float x=xa,y=ya;

glClear (GL_COLOR_BUFFER_BIT);

glColor3f (0.0, 1.0, 0.0);
glBegin(GL_POINTS);
glVertex2i(x,y);
int p =p0;
int k;
for(k=0;k<dx;k++)
{
if(p<0)
{
x = x+1;
glVertex2i(x,y);
}

else
{
    x = x+1; y = y+1;
    glVertex2i(x,y);
}
}

glEnd();
glFlush();
}

void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-100.0, 100.0, -100.0, 100.0, -1.0, 1.0);
}

int main(int argc, char** argv)
{
printf("Enter the points\n(X1,Y1,X2,Y2):-\n");
scanf("%d %d %d %d",&xa,&ya,&xb,&yb);
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow ("Breshanman Line Algorithm ");
init ();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}

But any printf command does not show the message on the console, I tested other code using OpenGL with printf and got the same result. The CodeBlocks doesnt show any error.

user1118321
  • 25,567
  • 4
  • 55
  • 86
  • Which `printf("something")`? – Reigertje Jan 04 '16 at 17:52
  • sorry, i meant any printf command used in the code. –  Jan 04 '16 at 17:55
  • 1
    Do you actually have a console window? – Nicol Bolas Jan 04 '16 at 18:01
  • no, theres only graphical window where everything works fine. But how is used printf in the example I thought I'd see something in a console window. –  Jan 04 '16 at 18:27
  • 3
    @alekar in case of windows applications, you need to manually create console window with `AllocConsole` (or `AttachConsole` of other process), and redirect `std*` streams to this console. http://stackoverflow.com/questions/34539135/how-do-i-print-to-the-console-while-an-sdl-2-program-is-running is a similar question, check it out – keltar Jan 04 '16 at 18:34

1 Answers1

0

Worked when I added the libraries gdi32, comdlg32 and user32 to the link libraries.