1. Post #3121


    Buttons and checkboxes!
    (No idea why plural because there's only one of each..)
    Reply With Quote Edit / Delete Windows 8 Netherlands Show Events Programming King Programming King x 2Artistic Artistic x 1Winner Winner x 1 (list)

  2. Post #3122
    Gold Member
    KillerJaguar's Avatar
    October 2006
    2,922 Posts
    How do you guys record your stuff?
    Reply With Quote Edit / Delete Windows 7 United States Show Events Agree Agree x 1 (list)

  3. Post #3123
    How do you guys record your stuff?
    > Fraps
    > Convert to WebM with Miro
    > Put in Dropbox public folder
    > Copy link
    > Paste in [vid] tags
    > ???
    > Profit
    Reply With Quote Edit / Delete Windows 8 Netherlands Show Events Informative Informative x 2Zing Zing x 1 (list)

  4. Post #3124
    HQRSE FUCKER
    ief014's Avatar
    September 2009
    3,047 Posts
    How do you guys record your stuff?
    Fraps,
    ffmpeg -i "vid.avi" -b 1M "vid.webm"
    Reply With Quote Edit / Delete Windows 7 Germany Show Events Winner Winner x 7Informative Informative x 1 (list)

  5. Post #3125
    open.gl
    Overv's Avatar
    February 2007
    7,431 Posts
    Its more like learning how to use the key to start the Carr instead of having somebody else to do it for you.

    Its an OpenGL tutorial you learn people OpenGL, OpenGL exists beyond C++, i don't see why you would want to learn people to fiddle with the SFML library to create a window for you.
    Because the code before the context creation is not part of the OpenGL spec. When you learn how to use wglCreateContext, you aren't learning how to use OpenGL, you are learning how to use the Win32 API.
    Reply With Quote Edit / Delete Windows 7 Netherlands Show Events Agree Agree x 3 (list)

  6. Post #3126
    Facepunch's Local Lycanthrope
    Contron's Avatar
    December 2008
    1,759 Posts
    I'm currently trying to make some kind of Java chat client/server application.



    Nothing networked works as of yet, although it's probably the first GUI in Java that I've made that doesn't look too bad
    Reply With Quote Edit / Delete Windows 7 Jersey Show Events

  7. Post #3127
    ASK ME ABOUT MY PLAYBOOK INSTEAD OF COLLEGE
    icantread49's Avatar
    April 2011
    1,616 Posts
    how about you store them as the exponent with 4 bits each?
    why would i increase code complexity to shave off a pixel's worth of bytes considering the rest of the file is 250k+ pixels worth of uncompressed RGB(A) data?
    Reply With Quote Edit / Delete Windows XP United States Show Events Agree Agree x 1 (list)

  8. Post #3128
    I made WAYWO a better place
    OldFusion's Avatar
    September 2011
    1,311 Posts
    Because the code before the context creation is not part of the OpenGL spec. When you learn how to use wglCreateContext, you aren't learning how to use OpenGL, you are learning how to use the Win32 API.
    How is learning how to create the context on a popular platform not related to OpenGL?
    Reply With Quote Edit / Delete Windows 7 United States Show Events Dumb Dumb x 1 (list)

  9. Post #3129
    Gold Member
    pebkac's Avatar
    January 2009
    2,576 Posts
    Well now with world set to:
    Code:
    colors = [['red', 'green', 'green', 'red' , 'red'],
              ['red', 'red', 'green', 'red', 'red'],
              ['red', 'red', 'green', 'green', 'red'],
              ['red', 'red', 'red', 'red', 'red']]
    and the measurements it detects are:
    Code:
    measurements = ['green', 'green', 'green' ,'green', 'green']
    with motions:
    Code:
    motions = [[0,0],[0,1],[1,0],[1,0],[0,1]]
    with accuracy
    Code:
    sensor_right = 0.7
    
    p_move = 0.8
    I get the result:
    For all of you wondering about this, it's actually a homework assignment from a free online robotics AI class that just started last week:
    http://www.udacity.com/overview/Course/cs373

    It's supposed to teach you how to program a car that can navigate by itself (it probably won't go much into the fine details, but it should give you a good understanding of the core principles and algorithms used for that) and it's taught by the same professor that did the Stanford's online AI class last year. If you did the previous AI class, you'll definitely enjoy this one, it's much more polished, explains the content really well step-by-step and even has nicely integrated programming assignments.
    Reply With Quote Edit / Delete Windows Vista Slovenia Show Events Informative Informative x 3 (list)

  10. Post #3130
    open.gl
    Overv's Avatar
    February 2007
    7,431 Posts
    How is learning how to create the context on a popular platform not related to OpenGL?
    It is related to OpenGL, but it is a cumbersome process and not related to the actual operation of OpenGL. The whole advantage of OpenGL is that it's cross-platform and you don't want to take away that advantage by writing OS-specific code.

    It is fun as an exercise for later, but it's not something a beginner should dive into.
    Reply With Quote Edit / Delete Windows 7 Netherlands Show Events Agree Agree x 3Disagree Disagree x 1 (list)

  11. Post #3131
    Gold Member
    Bambo.'s Avatar
    April 2011
    486 Posts
    How do you guys record your stuff?
    On a side note, for anyone using OS X ( or anything else that uses quicktime I THINK, DON'T QOTE ME ) you can record your screen by using quicktime.



    Then you can easily convert the video to various formats using... http://www.mirovideoconverter.com/

    I do not know if anyone else knows this so I thought i'd share it anyway.
    Reply With Quote Edit / Delete Mac United Kingdom Show Events

  12. Post #3132
    Gulen's Avatar
    December 2011
    2,545 Posts
    I have no idea what Latex is (except from the material), but why aren't you doing this is VB.net or whatever it is that Office uses?
    Reply With Quote Edit / Delete Mac Norway Show Events

  13. Post #3133
    Follow me on GitHub!
    Ziks's Avatar
    June 2011
    1,982 Posts
    Tip for anyone that might need something like this.
    Calculating n^m can be done in log m complexity by squaring.
    The actual algorithm is
    function Power (n, m)
    {
        result = 1;
        while (m > 0)
        {
            if (m % 2 == 1) result *= n;
            m >>= 1;
            n *= n;
        }
        return result;
    }

    Now for how it works.
    Every power can be expressed as either 2k or 2k + 1.
    That means that you can write 4^9 as 4^(4 * 2 + 1).
    You continue doing that until you have 4^(((2 * 2) * 2) + 1)
    The above code is does that gradually, going from outside to the inside.
    In case of m = 9, it would first multiply the result(1) with n(let's say 4) because 9 % 1 == 1.
    Then it divides 9 with 2 (the right shift operator, m is now 4) and squares n (n is now 16).
    4 % 2 == 0 so it just divides it with 2 and squares n again (n is now 256, m is 2).
    Again, m % 2 == 0, just divide with 2 and square again (n is 65536, m is 1)
    In the last step, m % 2 == 1 (as it always will be in the last step) and we finally multiply the result with n. 4 * 65536 = 262144 = 4 ^ 9

    The whole process takes 5 multiplications instead of 9. So it's even beneficial for small numbers. Naturally it performs many times better for large numbers.
    A bit late, but use ( m & 1 == 1 ) instead of ( m % 2 == 1 ). Unless I'm mistaken, modulo will require a division, which is pretty expensive.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  14. Post #3134
    Gold Member
    synthiac's Avatar
    June 2007
    1,081 Posts
    why would i increase code complexity to shave off a pixel's worth of bytes considering the rest of the file is 250k+ pixels worth of uncompressed RGB(A) data?
    lol idk v:)v

    Edited:

    > Put in Dropbox public folder
    terrible idea
    Reply With Quote Edit / Delete Windows 7 United States Show Events Dumb Dumb x 4Agree Agree x 1 (list)

  15. Post #3135
    Gold Member
    Socram's Avatar
    June 2006
    1,815 Posts
    Ugh my programming teacher just told us that he thinks "C++ and C will be completely dead within the 5 or so years due to the power and depth of Python."

    Oh boy...
    Reply With Quote Edit / Delete Windows 7 United States Show Events Funny Funny x 40 (list)

  16. Post #3136
    Gold Member
    Darwin226's Avatar
    January 2009
    4,036 Posts
    A bit late, but use ( m & 1 == 1 ) instead of ( m % 2 == 1 ). Unless I'm mistaken, modulo will require a division, which is pretty expensive.
    Compilers usually optimize that. I did it with a modulo so it's easier to understand (or not, depending how you look at it).
    Reply With Quote Edit / Delete Windows 7 Croatia Show Events Disagree Disagree x 1 (list)

  17. Post #3137
    Gold Member
    synthiac's Avatar
    June 2007
    1,081 Posts
    they call it python because it feels like you're being constricted by one when you use it
    Reply With Quote Edit / Delete Windows 7 United States Show Events Funny x 30Dumb x 4Zing x 1Optimistic x 1Agree x 1 (list)

  18. Post #3138
    Gold Member
    Darwin226's Avatar
    January 2009
    4,036 Posts
    Ugh my programming teacher just told us that he thinks "C++ and C will be completely dead within the 5 or so years due to the power and depth of Python."

    Oh boy...
    Honestly, he might not be too far off with C++.
    Seeing as C will always have it's place in a lot of things. C++ might lose it's title as the "language in which games are made".
    There are already alternatives that are much easier to work with with very little performance loss.
    Reply With Quote Edit / Delete Windows 7 Croatia Show Events Disagree Disagree x 2Agree Agree x 1Funny Funny x 1 (list)

  19. Post #3139
    Gold Member
    Lexic's Avatar
    March 2009
    6,118 Posts
    I'm using SDL at the moment, but SDL 1.3/2.0/Hg is far from ready for use, and SDL 1.2 is a little dated. Is GLFW recommended over SDL? What more does it offer?
    GLFW gives you an ultra light-weight no-frills simple and basic way of opening an OpenGL context and receive user input. (Keyboard/mouse/joystick.)
    Everything else is up to you. (Don't use the texture loading facilities, they're terrible. Try something like stb_image.)
    I really like it. The only blot is the complete lack of error reporting. If it fails, you have to use a debugger to find out why.
    Reply With Quote Edit / Delete Mac United Kingdom Show Events Agree Agree x 1 (list)

  20. Post #3140
    Gold Member
    Darwin226's Avatar
    January 2009
    4,036 Posts
    The Python part is obviously bullshit.
    Reply With Quote Edit / Delete Windows 7 Croatia Show Events Optimistic Optimistic x 1 (list)

  21. Post #3141
    Iskuri's Avatar
    January 2009
    340 Posts
    Just a quick update for those who care, I'm starting to play around with reinforcement learning AI now, and will probably have some cool results soon, I have a few ideas that would be very cool to get working with it. :)
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  22. Post #3142
    Gold Member
    Socram's Avatar
    June 2006
    1,815 Posts
    The Python part is obviously bullshit.
    Yeah that was the part that really bothered me, he's been saying stupid shit like this all year.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  23. Post #3143
    ASK ME ABOUT MY PLAYBOOK INSTEAD OF COLLEGE
    icantread49's Avatar
    April 2011
    1,616 Posts
    Honestly, he might not be too far off with C++.
    Seeing as C will always have it's place in a lot of things. C++ might lose it's title as the "language in which games are made".
    There are already alternatives that are much easier to work with with very little performance loss.
    C/C++ aren't ever going anywhere, enjoy finding a language to write a game in that runs on multiple platforms, including mobile platforms, without resorting to virtualization
    Reply With Quote Edit / Delete Windows XP United States Show Events Agree Agree x 4 (list)

  24. Post #3144
    Gold Member
    Darwin226's Avatar
    January 2009
    4,036 Posts
    Compilers usually optimize that. I did it with a modulo so it's easier to understand (or not, depending how you look at it).
    I did a benchmark in C#. Apparently % 2 is even faster than & 1. I have no idea why but there it is.
    Similarly, % 1024 is faster than & 1023.
    			var timer = new Stopwatch();
    			timer.Start();
    			int a;
    			for (int i = 0; i < 10000000; ++i)
    			{
    				a = 123456789 % 2; 
    			}
    			timer.Stop();
    			Console.WriteLine((float)timer.ElapsedTicks / Stopwatch.Frequency * 1000);
    			timer.Restart();
    			for (int i = 0; i < 10000000; ++i)
    			{
    				a = 123456789 & 1;
    			}
    			timer.Stop();
    			Console.WriteLine((float)timer.ElapsedTicks / Stopwatch.Frequency * 1000);

    Edit:
    Ignore the above, I'm an idiot.
    Reply With Quote Edit / Delete Windows 7 Croatia Show Events Disagree Disagree x 2Informative Informative x 1 (list)

  25. Post #3145
    ASK ME ABOUT MY PLAYBOOK INSTEAD OF COLLEGE
    icantread49's Avatar
    April 2011
    1,616 Posts
    that benchmark doesn't make any sense at all
    Reply With Quote Edit / Delete Windows XP United States Show Events Agree Agree x 1Dumb Dumb x 1 (list)

  26. Post #3146
    Gold Member
    Darwin226's Avatar
    January 2009
    4,036 Posts
    that benchmark doesn't make any sense at all
    How exactly?
    Reply With Quote Edit / Delete Windows 7 Croatia Show Events

  27. Post #3147
    Gold Member
    synthiac's Avatar
    June 2007
    1,081 Posts
    I did a benchmark in C#. Apparently % 2 is even faster than & 1. I have no idea why but there it is.
    Similarly, % 1024 is faster than & 1023.
    			var timer = new Stopwatch();
    			timer.Start();
    			int a;
    			for (int i = 0; i < 10000000; ++i)
    			{
    				a = 123456789 % 2; 
    			}
    			timer.Stop();
    			Console.WriteLine((float)timer.ElapsedTicks / Stopwatch.Frequency * 1000);
    			timer.Restart();
    			for (int i = 0; i < 10000000; ++i)
    			{
    				a = 123456789 & 1;
    			}
    			timer.Stop();
    			Console.WriteLine((float)timer.ElapsedTicks / Stopwatch.Frequency * 1000);
    would the optimizer not turn (123456789 % 2) into 1?
    Reply With Quote Edit / Delete Windows 7 United States Show Events Agree Agree x 8 (list)

  28. Post #3148
    Andrew McWatters
    Dennab
    March 2011
    4,658 Posts
    Because the code before the context creation is not part of the OpenGL spec. When you learn how to use wglCreateContext, you aren't learning how to use OpenGL, you are learning how to use the Win32 API.
    I'd rather learn how to use OpenGL as close to pure OpenGL as possible, and not through some third-party library or something.

    It reminds me of learning Lua through Garry's Mod all over again. There's nothing wrong with it, but there are some bastardized things about it. For instance, you may never touch some aspects of Lua considering you have the entire GMod API to focus on rather than doing things like creating your own OO model for pure-Lua classes.

    I don't know diddly shit about OpenGL, but I feel like using one of these third-party frameworks would be somewhat similar in some regard.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Disagree Disagree x 1 (list)

  29. Post #3149
    hOnK :o)
    i300's Avatar
    December 2009
    3,987 Posts
    Yeah that was the part that really bothered me, he's been saying stupid shit like this all year.
    Is the course a basic high school programming class, or a college programming course? Python is sort of fun to write but it really isn't practical for anything over some quick tests or some bullshit. (Whoops, I was wrong. I guess I'll be looking more into python in the future. Some stuff sounds pretty neat!)
    Reply With Quote Edit / Delete Mac United States Show Events

  30. Post #3150
    Gold Member
    iPope's Avatar
    October 2008
    1,774 Posts
    Is the course a basic high school programming class, or a college programming course? Python is sort of fun to write but it really isn't practical for anything over some quick tests or some bullshit.
    This is not true. Python is used extensivly in web programming, scientific programming, mathematical programming and just plain old coding applications for people to use.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events Agree Agree x 11 (list)

  31. Post #3151
    Gold Member
    Lexic's Avatar
    March 2009
    6,118 Posts
    I'd rather learn how to use OpenGL as close to pure OpenGL as possible, and not through some third-party library or something.

    It reminds me of learning Lua through Garry's Mod all over again. There's nothing wrong with it, but there are some bastardized things about it. For instance, you may never touch some aspects of Lua considering you have the entire GMod API to focus on rather than doing things like creating your own OO model for pure-Lua classes.

    I don't know diddly shit about OpenGL, but I feel like using one of these third-party frameworks would be somewhat similar in some regard.
    r u shuuuuur?

    Without using a helper library: (Actually using a helper library, but an official one)
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <unistd.h>
    #include <X11/Xlib.h>
    #include <X11/Xutil.h>
    #include <GL/gl.h>
    #include <GL/glx.h>
     
    #define GLX_CONTEXT_MAJOR_VERSION_ARB       0x2091
    #define GLX_CONTEXT_MINOR_VERSION_ARB       0x2092
    typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
     
    // Helper to check for extension string presence.  Adapted from:
    //   http://www.opengl.org/resources/features/OGLextensions/
    static bool isExtensionSupported(const char *extList, const char *extension)
     
    {
     
      const char *start;
      const char *where, *terminator;
     
      /* Extension names should not have spaces. */
      where = strchr(extension, ' ');
      if ( where || *extension == '\0' )
        return false;
     
      /* It takes a bit of care to be fool-proof about parsing the
         OpenGL extensions string. Don't be fooled by sub-strings,
         etc. */
      for ( start = extList; ; ) {
        where = strstr( start, extension );
     
        if ( !where )
          break;
     
        terminator = where + strlen( extension );
     
        if ( where == start || *(where - 1) == ' ' )
          if ( *terminator == ' ' || *terminator == '\0' )
            return true;
     
        start = terminator;
      }
     
      return false;
    }
     
    static bool ctxErrorOccurred = false;
    static int ctxErrorHandler( Display *dpy, XErrorEvent *ev )
    {
        ctxErrorOccurred = true;
        return 0;
    }
     
    int main (int argc, char ** argv)
    {
      Display *display = XOpenDisplay(0);
     
      if ( !display )
      {
        printf( "Failed to open X display\n" );
        exit(1);
      }
     
      // Get a matching FB config
      static int visual_attribs[] =
        {
          GLX_X_RENDERABLE    , True,
          GLX_DRAWABLE_TYPE   , GLX_WINDOW_BIT,
          GLX_RENDER_TYPE     , GLX_RGBA_BIT,
          GLX_X_VISUAL_TYPE   , GLX_TRUE_COLOR,
          GLX_RED_SIZE        , 8,
          GLX_GREEN_SIZE      , 8,
          GLX_BLUE_SIZE       , 8,
          GLX_ALPHA_SIZE      , 8,
          GLX_DEPTH_SIZE      , 24,
          GLX_STENCIL_SIZE    , 8,
          GLX_DOUBLEBUFFER    , True,
          //GLX_SAMPLE_BUFFERS  , 1,
          //GLX_SAMPLES         , 4,
          None
        };
     
      int glx_major, glx_minor;
     
      // FBConfigs were added in GLX version 1.3.
      if ( !glXQueryVersion( display, &glx_major, &glx_minor ) || 
           ( ( glx_major == 1 ) && ( glx_minor < 3 ) ) || ( glx_major < 1 ) )
      {
        printf( "Invalid GLX version" );
        exit(1);
      }
     
      printf( "Getting matching framebuffer configs\n" );
      int fbcount;
      GLXFBConfig *fbc = glXChooseFBConfig( display, DefaultScreen( display ), 
                                            visual_attribs, &fbcount );
      if ( !fbc )
      {
        printf( "Failed to retrieve a framebuffer config\n" );
        exit(1);
      }
      printf( "Found %d matching FB configs.\n", fbcount );
     
      // Pick the FB config/visual with the most samples per pixel
      printf( "Getting XVisualInfos\n" );
      int best_fbc = -1, worst_fbc = -1, best_num_samp = -1, worst_num_samp = 999;
     
      int i;
      for ( i = 0; i < fbcount; i++ )
      {
        XVisualInfo *vi = glXGetVisualFromFBConfig( display, fbc[i] );
        if ( vi )
        {
          int samp_buf, samples;
          glXGetFBConfigAttrib( display, fbc[i], GLX_SAMPLE_BUFFERS, &samp_buf );
          glXGetFBConfigAttrib( display, fbc[i], GLX_SAMPLES       , &samples  );
     
          printf( "  Matching fbconfig %d, visual ID 0x%2x: SAMPLE_BUFFERS = %d,"
                  " SAMPLES = %d\n", 
                  i, vi -> visualid, samp_buf, samples );
     
          if ( best_fbc < 0 || samp_buf && samples > best_num_samp )
            best_fbc = i, best_num_samp = samples;
          if ( worst_fbc < 0 || !samp_buf || samples < worst_num_samp )
            worst_fbc = i, worst_num_samp = samples;
        }
        XFree( vi );
      }
     
      GLXFBConfig bestFbc = fbc[ best_fbc ];
     
      // Be sure to free the FBConfig list allocated by glXChooseFBConfig()
      XFree( fbc );
     
      // Get a visual
      XVisualInfo *vi = glXGetVisualFromFBConfig( display, bestFbc );
      printf( "Chosen visual ID = 0x%x\n", vi->visualid );
     
      printf( "Creating colormap\n" );
      XSetWindowAttributes swa;
      Colormap cmap;
      swa.colormap = cmap = XCreateColormap( display,
                                             RootWindow( display, vi->screen ), 
                                             vi->visual, AllocNone );
      swa.background_pixmap = None ;
      swa.border_pixel      = 0;
      swa.event_mask        = StructureNotifyMask;
     
      printf( "Creating window\n" );
      Window win = XCreateWindow( display, RootWindow( display, vi->screen ), 
                                  0, 0, 100, 100, 0, vi->depth, InputOutput, 
                                  vi->visual, 
                                  CWBorderPixel|CWColormap|CWEventMask, &swa );
      if ( !win )
      {
        printf( "Failed to create window.\n" );
        exit(1);
      }
     
      // Done with the visual info data
      XFree( vi );
     
      XStoreName( display, win, "GL 3.0 Window" );
     
      printf( "Mapping window\n" );
      XMapWindow( display, win );
     
      // Get the default screen's GLX extension list
      const char *glxExts = glXQueryExtensionsString( display,
                                                      DefaultScreen( display ) );
     
      // NOTE: It is not necessary to create or make current to a context before
      // calling glXGetProcAddressARB
      glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0;
      glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)
               glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
     
      GLXContext ctx = 0;
     
      // Install an X error handler so the application won't exit if GL 3.0
      // context allocation fails.
      //
      // Note this error handler is global.  All display connections in all threads
      // of a process use the same error handler, so be sure to guard against other
      // threads issuing X commands while this code is running.
      ctxErrorOccurred = false;
      int (*oldHandler)(Display*, XErrorEvent*) =
          XSetErrorHandler(&ctxErrorHandler);
     
      // Check for the GLX_ARB_create_context extension string and the function.
      // If either is not present, use GLX 1.3 context creation method.
      if ( !isExtensionSupported( glxExts, "GLX_ARB_create_context" ) ||
           !glXCreateContextAttribsARB )
      {
        printf( "glXCreateContextAttribsARB() not found"
                " ... using old-style GLX context\n" );
        ctx = glXCreateNewContext( display, bestFbc, GLX_RGBA_TYPE, 0, True );
      }
     
      // If it does, try to get a GL 3.0 context!
      else
      {
        int context_attribs[] =
          {
            GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
            GLX_CONTEXT_MINOR_VERSION_ARB, 0,
            //GLX_CONTEXT_FLAGS_ARB        , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
            None
          };
     
        printf( "Creating context\n" );
        ctx = glXCreateContextAttribsARB( display, bestFbc, 0,
                                          True, context_attribs );
     
        // Sync to ensure any errors generated are processed.
        XSync( display, False );
        if ( !ctxErrorOccurred && ctx )
          printf( "Created GL 3.0 context\n" );
        else
        {
          // Couldn't create GL 3.0 context.  Fall back to old-style 2.x context.
          // When a context version below 3.0 is requested, implementations will
          // return the newest context version compatible with OpenGL versions less
          // than version 3.0.
          // GLX_CONTEXT_MAJOR_VERSION_ARB = 1
          context_attribs[1] = 1;
          // GLX_CONTEXT_MINOR_VERSION_ARB = 0
          context_attribs[3] = 0;
     
          ctxErrorOccurred = false;
     
          printf( "Failed to create GL 3.0 context"
                  " ... using old-style GLX context\n" );
          ctx = glXCreateContextAttribsARB( display, bestFbc, 0, 
                                            True, context_attribs );
        }
      }
     
      // Sync to ensure any errors generated are processed.
      XSync( display, False );
     
      // Restore the original error handler
      XSetErrorHandler( oldHandler );
     
      if ( ctxErrorOccurred || !ctx )
      {
        printf( "Failed to create an OpenGL context\n" );
        exit(1);
      }
     
      // Verifying that context is a direct context
      if ( ! glXIsDirect ( display, ctx ) )
      {
        printf( "Indirect GLX rendering context obtained\n" );
      }
      else
      {
        printf( "Direct GLX rendering context obtained\n" );
      }
     
      printf( "Making context current\n" );
      glXMakeCurrent( display, win, ctx );
     
      glClearColor ( 0, 0.5, 1, 1 );
      glClear ( GL_COLOR_BUFFER_BIT );
      glXSwapBuffers ( display, win );
     
      sleep( 1 );
     
      glClearColor ( 1, 0.5, 0, 1 );
      glClear ( GL_COLOR_BUFFER_BIT );
      glXSwapBuffers ( display, win );
     
      sleep( 1 );
     
      glXMakeCurrent( display, 0, 0 );
      glXDestroyContext( display, ctx );
     
      XDestroyWindow( display, win );
      XFreeColormap( display, cmap );
      XCloseDisplay( display );
    }
    Using a helper library:
    Code:
    // Include standard headers
    #include <stdio.h>
    #include <stdlib.h>
    
    // Include GLEW
    #include <GL/glew.h>
    
    // Include GLFW
    #include <GL/glfw.h>
    
    // Include GLM
    #include <glm/glm.hpp>
    using namespace glm;
    
    int main( void )
    {
        // Initialise GLFW
        if( !glfwInit() )
        {
            fprintf( stderr, "Failed to initialize GLFW\n" );
            return -1;
        }
    
        glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
        glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
        glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
            glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    
        // Open a window and create its OpenGL context
        if( !glfwOpenWindow( 1024, 768, 0,0,0,0, 32,0, GLFW_WINDOW ) )
        {
            fprintf( stderr, "Failed to open GLFW window\n" );
            glfwTerminate();
            return -1;
        }
    
            // Initialize GLEW
            if (glewInit() != GLEW_OK) {
                    fprintf(stderr, "Failed to initialize GLEW\n");
                    return -1;
            }
    
            glfwSetWindowTitle( "Tutorial 01" );
    
            // Dark blue background
            glClearColor(0.0f, 0.0f, 0.3f, 0.0f);
    
    
            // Swap buffers
            glfwSwapBuffers();
    
        // Close OpenGL window and terminate GLFW
        glfwTerminate();
    
        return 0;
    }
    Reply With Quote Edit / Delete Mac United Kingdom Show Events Agree Agree x 8Disagree Disagree x 1Winner Winner x 1 (list)

  32. Post #3152
    hOnK :o)
    i300's Avatar
    December 2009
    3,987 Posts
    This is not true. Python is used extensivly in web programming, scientific programming, mathematical programming and just plain old coding applications for people to use.
    Really? Jee, thats cool I geuss. The more you know.
    Reply With Quote Edit / Delete Mac United States Show Events Friendly Friendly x 2Zing Zing x 1 (list)

  33. Post #3153
    Gold Member
    Darwin226's Avatar
    January 2009
    4,036 Posts
    would the optimizer not turn (123456789 % 2) into 1?
    Hmmm. You're right.
    Well it seems that I'm an idiot. I'll redo it.
    Reply With Quote Edit / Delete Windows 7 Croatia Show Events Friendly Friendly x 2 (list)

  34. Post #3154
    Gold Member
    windwakr's Avatar
    September 2009
    4,597 Posts
    A bit late, but use ( m & 1 == 1 ) instead of ( m % 2 == 1 ). Unless I'm mistaken, modulo will require a division, which is pretty expensive.
    The modulo there doesn't require a division. Because the 2 never changes it can be optimized down:

    "m % 2":
    Code:
    ;eax = number to be modulo'd by 2
            and     eax, -2147483647                        ; 80000001H
            jns     SHORT $LN6@main
            dec     eax
            or      eax, -2                                 ; fffffffeH
            inc     eax
    $LN6@main:
    Everything past the "jns SHORT $LN6@main" is for negative numbers and skipped over if the number was positive.



    "m & 1":
    Code:
    test     eax, 1   ;Does the same thing as "and eax, 1" for this purpose
    So the only difference between "m % 2" and "m & 1" for positive numbers is a conditional jump.


    But that's just because the divisor is a static number. It would use an expensive division if the divisor could change.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Informative Informative x 3 (list)

  35. Post #3155
    Gold Member
    Socram's Avatar
    June 2006
    1,815 Posts
    Is the course a basic high school programming class, or a college programming course? Python is sort of fun to write but it really isn't practical for anything over some quick tests or some bullshit.
    This is a college level course, they actually added it this year for the first time. Apparently the intro to programming course in C++ was too fast paced for some so now they have this "Intro to Intro to programming" type class, which spends first 5 weeks on how to use the command line in Linux (riveting stuff...) and the remainder teaching basic programming concepts in Python. I have no qualms with Python mind you, it's a good language for what its for, its just his statement of it replacing C and C++ that irked me.

    It sucks taking an intro class like this when you already know how to program (in my opinion) fairly well. I hate to sound elitist but god there are some idiots in here.

    Also if anyone cares this is not a CS major, it's an visual effects major that includes like 12 hours or so of programming. I'm thinking I might try for a minor is CS though.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Informative Informative x 1 (list)

  36. Post #3156
    Gold Member
    Darwin226's Avatar
    January 2009
    4,036 Posts
    Ok, changed it to rand.Next(). Same result (only slower in both cases of course).
    Reply With Quote Edit / Delete Windows 7 Croatia Show Events

  37. Post #3157
    Gold Member
    Bambo.'s Avatar
    April 2011
    486 Posts
    I really want to learn assembly, but I really can't think of anything that I could make which couldn't be done easily in a different language...
    Reply With Quote Edit / Delete Mac United Kingdom Show Events Agree Agree x 1 (list)

  38. Post #3158
    Andrew McWatters
    Dennab
    March 2011
    4,658 Posts
    r u shuuuuur?
    clearly you don't understand how much of a masochist i am; maybe writing my own version of a mod from the ground up so i can have things my own way isn't a clear depiction of this
    Reply With Quote Edit / Delete Windows 7 United States Show Events Funny Funny x 6 (list)

  39. Post #3159
    dajoh's Avatar
    March 2011
    625 Posts
    I really want to learn assembly, but I really can't think of anything that I could make which couldn't be done easily in a different language...
    CPU feature detection.
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events Informative Informative x 2Agree Agree x 2Useful Useful x 1 (list)

  40. Post #3160

    August 2011
    192 Posts
    Ok, changed it to rand.Next(). Same result (only slower in both cases of course).
    did some tests, even in C modulo was a little bit faster, checked the assembly code and it wasn't optimised out.
    Reply With Quote Edit / Delete Windows 7 Switzerland Show Events