I am new to OPENGL and Im trying to run a sample code in Visual Studio C++.The code compiles. When I run the code , I see a black screen for a second , and disappears. I am just trying to draw a simple line.Please Help !!!
Here is the code.
void DrawLine( int ax, int ay, int bx, int by, int width, int r, int g, int b, int a )
glColor4ub( r, g, b, a);
glVertex2i( ax, ay);
glVertex2i( bx, by);
DrawLine( 492, 384, 532, 384, 3, 0, 255, 100, 255);
Please read the Forum Posting Guidelines specifically on how to use [ code]/[ /code] tags around source code.
Your program only draws the line, then exits (i.e. reaches end of main()), so what you are seeing is sort of expected.
If that is the entirety of your code, you are also not creating an OpenGL context, so all OpenGL commands are invalid. I’d suggest you start by reading some tutorials (suggestions are on the wiki, bottom third of the page) to get a better understanding of the basics of an OpenGL program.
I doubt you’re creating a graphics window at all with your code.
I’m guessing that all you’re seeing is a console window.
Use source code for the first 1 or 2 NeHe Tutorials to correctly create an OpenGL window.
(i.e. one that doesn’t instantly disappear).
Just copy the code, compile, link, and run it.
Once you can do that, drawing a line will be easy.