About Me

My name is Ali Badereddin. I’m Lebanese, born in Gabon and raised in Lebanon. After completing my BS in computer science at AUB, I moved to Dubai and worked as a technical consultant in the supply chain industry. Later I joined Microsoft and moved to Vancouver. Now, I enjoy living in Seattle and working with the SharePoint team. My interests include parkour, scientific visualization, reading, active dreaming, running, and Wing Chun.

    • Frank
    • September 4th, 2008

    Hi Ali,
    I was checking out your GLUI application and had a question. I am creating plugins for Motionbuilder using regular openGL. Your program looks great since I wont have to create all the controls I need from scratch. The only issue is your application is built on top of GLUT and thats where the problem starts. Inside motionbuilder when i create a plugin-in, it already creates a tool window for me along with all the system parameters for mouse, keyboard, etc. and it has its own system management for callbacks running thru the window it creates for me. How would I be able to incorporate GLUI without first creating a GLUT window or is there a way to pass my own window parameters as if they were coming from a GLUT window? I tried a few things but it seems without first creating a GLUT window nothing can move forward. Do you have some ideas how I could use GLUI and just bypass the GLUT window somehow?
    Thanks a lot,

    • saied
    • September 25th, 2010

    salam ali , i am saied from iran , i check your glu application . if you can please send me your graphic codes and e-books.

    • Hanan
    • December 9th, 2010

    Hello Eng. Ali;

    I was Happy to see your Blog about opengl Geometric primitives. it is really so helpful and written in easy way that can help beginners to exactly understand how to use OpenGl primitives.

    I have a aquestion, and wondering if you can help me. I am using Primitives opengl (lines) as I want to draw lines whenever the user specify using mouse, as i store corrdinates in a vector list and go over this list, but the problem i need these to be lines, not segments in other way use (glbegin(gl_line_strip) not glbegin(gl_lines), so the problem i face is that how to separate these lines based on events. in other words, as long as mouse is down drwa lines, once up, and down again in any where in the widnow can draw the lines withought connecting to the previous one.

    I am sorry, i know it is much talking for the fist time to comment on your blog, i just wanted to make sure you get the point am asking about.

    Thank you in advance;


  1. Hanan,

    I think you have the answer.. simply change the polygon mode from line strip to just lines. Let me know if you meant something else..

      • Hanan
      • December 27th, 2010

      actually I mean something else, I use Gl_line strip b/c i wanna it connected line, but when i use gl_lines it take each two points as one line, so it give me segments of lines that are nt connected, but my point i want when draw again when mouse button is down does not connect the new line with the previous drawn line.

      wish you got my point.

      Thank you so much for your time and consideration.

      • You’ll need a vector list of a vector list of coordinates… Think of this as a 3-dimensional array m x n x 3, where 3 respresents the number of coordinates (x, y, z), n is the number of lines in a set of consecutive lines, and m is the number of sets.

        Whenever the mouse is down, you create a new vector of points. On drawing, you draw all the sets of vectors..

        Hope that helps..

    • Hanan
    • December 28th, 2010

    this already wht I did from the beginning, I did create a vector list of 3D points,but did not try vector list of vector list, it is a good idea, I will do it, and reply when it works.

    Thank you so much for your time and consideration,greatly appreciate.

    • Hanan
    • January 13th, 2011

    Hello Eng. Ali;

    I would like to say thank you so much for the idea of vector list of vector list. I get it work with some other modifications.

    actually I have one more question if possible, I have created two separate planes in opengl window to draw different things, but the problem i have now I want to draw in real time on one of planes while disable drawing on other plane, i tried using glscissor, but still did not get what i want, could you help me with that.

    Thank you in advance.

    • Hanan
    • January 19th, 2011

    Hello Eng. Ali;

    actually I started to use opengl subwindow to get the different sections in main window, so i would like to know am i in the right direction as a way for my previous posted question.

    Thank you so much for help and consideration.

    • Akhilesh
    • March 16th, 2011

    i want help modifying this code please.

    1. i want to reduce the number of generated pixels to 400×200.
    2. i want it to generate with a scroll bar such that i can scroll back and forth through the generations (instead of it generating one by one with ‘g’ key, and not being able to view the previous images.
    3. I also want to know if there is any way to make the program play the generationss like a video. (instead of using the scroll bar metioned above)

    can you give me some help with this?
    i am going to be using ‘C language’ with the VS2010 Express compiler for compiling.
    i cannot seem to find a complete enough reference file on the internet for opengl’s glut.h/glut32.dll.

    // File Name : PixGen.c
    // Author : Ali BaderEddin
    // Created : December 2003
    // Modified : March 2010
    // Description : Generate new image with random colors on mouse click.


    // Avoid showing up the console window
    #pragma comment(linker,”/subsystem:\”windows\” /entry:\”mainCRTStartup\””)

    // constants representing the window size
    #define WINDOW_WIDTH 512
    #define WINDOW_HEIGHT 512

    // Initialization
    void init ();

    // Callback functions
    void display (void);
    void mouse (int button, int state, int x, int y);
    void keyboard (unsigned char key, int x, int y);

    // Support Functions
    void centerOnScreen ();

    // define the window position on screen
    int window_x;
    int window_y;

    // variable representing the window title
    char *window_title = “Image Generator”;

    // Tells whether to display the window full screen or not
    // Press Alt + Esc to exit a full screen.
    int full_screen = 0;

    // Generates a random image…
    void generateImage ();

    // Represents the pixel buffer in memory
    GLubyte buffer[WINDOW_WIDTH][WINDOW_HEIGHT][3];

    // Set OpenGL program initial state.
    void init ()
    glClearColor (0.0, 0.0, 0.0, 0.0);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    srand (time(NULL));

    // This function is passed to glutDisplayFunc in order to display
    // OpenGL contents on the window.
    void display (void)
    GL_UNSIGNED_BYTE, buffer);
    glutSwapBuffers ();

    // This function is passed to the glutMouseFunc and is called
    // whenever the mouse is clicked.
    void mouse (int button, int state, int x, int y)
    if (state == GLUT_DOWN)
    generateImage ();
    glutPostRedisplay ();

    // This function is passed to the glutKeyboardFunc and is called
    // whenever the user hits a key.
    void keyboard (unsigned char key, int x, int y)
    switch (key)
    case ‘g':
    generateImage ();
    glutPostRedisplay ();
    case 27:
    exit (0);

    // This function sets the window x and y coordinates
    // such that the window becomes centered
    void centerOnScreen ()
    window_x = (glutGet (GLUT_SCREEN_WIDTH) – WINDOW_WIDTH)/2;
    window_y = (glutGet (GLUT_SCREEN_HEIGHT) – WINDOW_HEIGHT)/2;

    // Generate new image with random colors
    void generateImage ()
    int i, j;

    for (i = 0; i < WINDOW_WIDTH; i++)
    for (j = 0; j < WINDOW_HEIGHT; j++)
    buffer[i][j][0] = (GLubyte) (rand () % 256);
    buffer[i][j][1] = (GLubyte) (rand () % 256);
    buffer[i][j][2] = (GLubyte) (rand () % 256);

    // Program Main method.
    void main (int argc, char **argv)
    // Connect to the windowing system
    glutInit(&argc, argv);

    // create a window with the specified dimensions
    glutInitWindowSize (WINDOW_WIDTH, WINDOW_HEIGHT);

    // Set the window x and y coordinates such that the
    // window becomes centered
    centerOnScreen ();

    // Position Window
    glutInitWindowPosition (window_x, window_y);

    // Set Display mode
    glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE);

    // Create window with the specified title
    glutCreateWindow (window_title);

    // View in full screen if the full_screen flag is on
    if (full_screen)
    glutFullScreen ();

    // Set OpenGL program initial state.

    // Set the callback functions
    glutDisplayFunc (display);
    glutKeyboardFunc (keyboard);
    glutMouseFunc (mouse);

    // Start GLUT event processing loop

    • Akhilesh
    • March 16th, 2011


    • Hanan
    • July 15th, 2011

    Hello Every one,

    I need help regarding collision Detection. I know there is no collision detection in OPenGl and I should use different algorithm as I-Collide/V-Collide/Swift.Bullet and so many different collision detection libraries, but actually I am totally lost and do not know which one i should use. I have developed 3d models and render it using opengl and need to apply collision detection for these models, but I do not know which Collision Detection Algo I can use.

    please if any materials, code samples, algorithms available, I would highly appreciate.

    • mohsen
    • August 7th, 2011

    hello ali
    i begin to learn opengl
    i bookmarked your blog ;-)

    • jithu
    • February 9th, 2012

    could u pls suggest some topics for my first open gl project in my college

  2. Thanks a lot for your explanation posted in codeproject, I am from Mexico where I live and have been working for years in AutoCad and developing tools on VLisp for Cad users, I love Math, Geometry and Programing, now a days I am trying for myself to develop a kind of Cad software within MFC which has been really really hard to understand and manipulate so I have been looking for easier options and… I found you. My question is: Is it possible to mix C++ & MFC classes and functions with openGL or we have to choose only one? I will have a lot of questions further on and I will apretiate your help. Fernando.

    • Sankar Erupuru
    • December 2nd, 2013


    Am a new joiner in packaging team. I have a setup.exe Could you please help me how to install and uninstall Visual Studio 2010 Professional in silent mode?

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: