PDA

View Full Version : Seeing just a black screen.. no output !!



rborgaonkar
04-30-2012, 10:44 AM
Hello All,

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.
#include "StdAfx.h"
#include <windows.h>
#include <gl/gl.h>

void DrawLine( int ax, int ay, int bx, int by, int width, int r, int g, int b, int a )
{
glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4ub( r, g, b, a);

glLineWidth(width);
glBegin(GL_LINES);
glVertex2i( ax, ay);
glVertex2i( bx, by);
glEnd();

glDisable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
}

void main()
{
DrawLine( 492, 384, 532, 384, 3, 0, 255, 100, 255);

}

carsten neumann
04-30-2012, 11:26 AM
Please read the Forum Posting Guidelines (http://www.opengl.org/discussion_boards/showthread.php/176139-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 (http://www.opengl.org/wiki/Getting_started), bottom third of the page) to get a better understanding of the basics of an OpenGL program.

Carmine
04-30-2012, 05:09 PM
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.