Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am fairly new to c/c++ but I do have experiance with directx and opengl with java and c#. My goal is to create a 2d game in c with under 2 pages of code. Most of what I have seen requires 3 pages of code to just get a window running.

I would like to know the shortest code to get a window running where I can draw lines. I believe this can be done in less lines with opengl versus directx. Is there maybe an api or framework i can use to shorten it more?

Also, it would be nice if the solution were cross platform compatible.

share|improve this question
A whole game in 2 pages? I doubt that. And most APIs come with some line drawing function. Oh, and looking at OpenGL/DirectX is veering wildly away from 'shortest way'. – The Communist Duck Nov 3 '10 at 17:49
Shortest way: printf("+----_____\n\ \ \ \ \ \ \ \ \ \ ---+\n"); – Trevor Powell Nov 21 '12 at 20:54
up vote 2 down vote accepted

GLUT might be what you're looking for. It is a cross platform Open GL wrapper that helps setting up the basics.

Hope this helps.

share|improve this answer
thanks! After visiting wikipedia for GLUT, I found SDL. It seems more appealing to me. However, it would be nice to hear some opinions on the matter since I have no idea which is better. – Mike Nov 2 '10 at 22:44
I found this: . It talks about the pros and cons of SDL vs GLUT vs GLFW vs Native. – Nailer Nov 2 '10 at 22:54

Also look at SDL. A good wrapper multiplatform to Directx (on Win)and OpenGl (on Linux and also Win ..). I'm using SDL and... it is easy to understand for a beginner!

For Sdl exists a binding to C# and Java. For C# is called. SDL.NET

share|improve this answer
SDL creates a window for you - different code depending on the platform, but the same basic functionality. Basic 2D graphics are supported - blitting is easy enough, and IIRC there's a simple line function. File formats need an extra library (SDL_Image?) with dependencies on libpng etc. Sound is a pain unless you add SDL_Mixer to the mix - simply getting multiple concurrent sound effects could overflow your two-pages budget. It's very easy to code for SDL, but not so easy to get all the libs and dependencies set up in a working build environment - at least not on Windows. – Steve314 Nov 12 '11 at 3:01 <- Making window, and drawing lines is very easy

share|improve this answer

Here is an example program that draws a line to a window using the cross platform library Qt. Includes have been omitted.

struct MyWindow: public QMainWindow

  MyWindow(QWidget *parent = 0, Qt::WFlags flags = 0){ui.setupUi(this);}

  void paintEvent(QPaintEvent *)
    QPainter painter(this);

    QLineF line(10.0, 80.0, 90.0, 20.0);

  Ui::MyWindow ui;

int main(int argc, char *argv[])
  QApplication a(argc, argv);
  MyWindow w;;
  return a.exec();

Note that this example does not use OpenGL. To render to OpenGL using the same draw calls simply derive a class from QGLWidget.

share|improve this answer

You might want to use Cairo to draw 2d graphics on any backend. You can combine it with SDL or OpenGL or GTK, as display-backend, or with .png or .svg or .pdf as file-backend, too.

share|improve this answer

Here's a basic GLUT app that draws lines

#include <gl/glut.h>
#include <math.h>

void render()

  for( double i = 0 ; i < 2*3.14159; i+=0.01 )
    double value1 = cos(i) ;
    double value2 = sin(i) ;
    glColor3d( fabs(value1), fabs(value1)*fabs(value2), fabs(value2) );
    glVertex2d( .2*value1*value2,.4*value2 ) ;
    glVertex2d( value1, value2 ) ;
  glEnd() ;

  glutSwapBuffers() ;

int main( int argc, char** argv )
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  glutCreateWindow("GLUT Window");

  glutDisplayFunc( render ); 
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.