Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Seeing just a black screen.. no output !!

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2012
    Posts
    1

    Seeing just a black screen.. no output !!

    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);

    }

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Posts
    720
    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.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    177
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •