• What are you working on? February 2012
    3,497 replies, posted
  • [QUOTE=Socram;34895870]Yeah that was the part that really bothered me, he's been saying stupid shit like this all year.[/QUOTE] Is the course a basic high school programming class, or a college programming course? [del]Python is sort of fun to write but it really isn't practical for anything over some quick tests or some bullshit.[/del] (Whoops, I was wrong. I guess I'll be looking more into python in the future. Some stuff sounds pretty neat!)
  • [QUOTE=i300;34896297]Is the course a basic high school programming class, or a college programming course? [B]Python is sort of fun to write but it really isn't practical for anything over some quick tests or some bullshit.[/B][/QUOTE] 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.
  • [QUOTE=amcfaggot;34896286]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 [i]wrong[/i] 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.[/QUOTE] 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 ); }[/code] 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; }[/code]
  • [QUOTE=iPope;34896373]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.[/QUOTE] Really? Jee, thats cool I geuss. The more you know.
  • [QUOTE=synthiac;34896279]would the optimizer not turn (123456789 % 2) into 1?[/QUOTE] Hmmm. You're right. Well it seems that I'm an idiot. I'll redo it.
  • [QUOTE=Ziks;34895620]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.[/QUOTE] 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: [/code] 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 [/code] 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.
  • [QUOTE=i300;34896297]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.[/QUOTE] 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.
  • Ok, changed it to rand.Next(). Same result (only slower in both cases of course).
  • 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...
  • [QUOTE=Lexic;34896433]r u shuuuuur?[/QUOTE] 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
  • [QUOTE=Bambo.;34896564]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...[/QUOTE] CPU feature detection.
  • [QUOTE=Darwin226;34896475]Ok, changed it to rand.Next(). Same result (only slower in both cases of course).[/QUOTE] did some tests, even in C modulo was a little bit faster, checked the assembly code and it wasn't optimised out.
  • I have a few hours experience in SFML. I'm going to try to make a tile engine. THIS SHALL END WELL edit: failed already
  • [QUOTE=Socram;34896473]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.[/QUOTE] Our first exercise session (for 2nd year College Physics) in C++ was already using classes and all that stuff. Skipped the Hello World stuff right away.
  • [QUOTE=Socram;34896473]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.[/QUOTE] Test out if given the opportunity, or sit back and enjoy what you can of the course. I think this upcoming semester I'll have time to take intro to C++, and while I don't see it being very entertaining, it'll give me the chance to blow time outside of the house.
  • In case anyone here cares, [url]http://travis-ci.org[/url] just added python and perl to their list of supported languages. I set it up for my build system (yeah I'm just gonna trudge through with it. I think I also figured out my performance issue :v:), and it's really neat. One of the PITA issues with python is getting a decent continuous integration system that "just works" and doesn't require the JVM to run, or a simple config system. I kind of wish they would use tox for generating information, but oh well. It works with python 3.2, that's good enough for me. I figured some of you here might want to use it for unit-tests or something.
  • [QUOTE=amcfaggot;34896749]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[/QUOTE] I'm surprised you're still in the win32 world then. The heady world of GUI Linux coding is so full of excessively complex required configuration that you'd probs pop a boner every time you opened your personally compiled and tweaked copy of vim/emacs with all your hand written plugins and cfg files.
  • [QUOTE=Lexic;34895763]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 [url=http://nothings.org/stb_image.c]stb_image[/url].) 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.[/QUOTE] Just out of curiosity, why should the texture loading routines be avoided? I already have a loader for uncompressed tga (written in C) and png (through libpng) images, and I can salvage my libjpeg, etc, code from another project. However, using the GLFW provided functions would shrink my codebase and it is appealing to me to make the most of the fewest number of libraries possible. At first I was concerned that GLFW might not be able to handle sRGB textures, but it looks like you can decode the images with GLFW separately and manually load the data into OpenGL.
  • [QUOTE=Nighley;34896821]did some tests, even in C modulo was a little bit faster, checked the assembly code and it wasn't optimised out.[/QUOTE] Are you positive that something wasn't being optimized out? The compiler optimizes out anything that's unused. [code] #include <windows.h> #include <iostream> #include <iomanip> using std::cout; using std::endl; using std::setprecision; double PCFreq = 0.0; __int64 CounterStart = 0; void StartCounter() { LARGE_INTEGER li; if(!QueryPerformanceFrequency(&li)) cout << "QueryPerformanceFrequency failed!\n"; PCFreq = double(li.QuadPart)/1000000.0; QueryPerformanceCounter(&li); CounterStart = li.QuadPart; } double GetCounter() { LARGE_INTEGER li; QueryPerformanceCounter(&li); return double(li.QuadPart-CounterStart)/PCFreq; } int main() { int m = 1; int a = 0; double l1 = 0.0; double l2 = 0.0; cout << "% 2 loop: "; for(int i = 0; i < 4; i++) { m = 1; StartCounter(); while(m != 0) { a += ((m % 2) != 0); //modulo can also return -1, so we do this to make both loops always add the same things. m += 1; } l1 += GetCounter(); } cout << setprecision (15) << (l1/4.0) <<" microseconds\n\n"; cout << "& 1 loop: "; for(int i = 0; i < 4; i++) { m = 1; StartCounter(); while(m != 0) { a += ((m & 1) != 0); //See the comment in the first loop. m += 1; } l2 += GetCounter(); } cout << setprecision (15) << (l2/4.0) << " microseconds\n"; m+=a; cout << a << endl; return 0; } [/code] Output: [code] % 2 loop: 5100429.43656247 microseconds & 1 loop: 2637060.52375372 microseconds 0 [/code] Ignore the 0 printed, I just have that so it doesn't optimize the loops out. Timing code from: [url]http://stackoverflow.com/questions/1739259/how-to-use-queryperformancecounter[/url] The code may not be great, but it shows that there is a measurable difference between "& 1" and "% 2", with "& 1" being much faster. [editline]...[/editline] This is with signed numbers, an unsigned "m" would result in the "% 2" and "& 1" being pretty much identical. [editline]...[/editline] Also, if you keep "m" signed but only deal with positive numbers(so it doesn't have to execute all the other instructions to preserve the sign), the "% 2" loop is ~3x slower. So, you should only use "% 2" when the dividend is unsigned.
  • I like coding shaders more than coding programs now... Please help me :c [url]http://glsl.heroku.com/e#1770.4[/url] I guess I do it because you can do more with less code, I mean 31 lines for this, including comments! Also since when did Gran PC have a green name?
  • [QUOTE=ROBO_DONUT;34897198]Just out of curiosity, why should the texture loading routines be avoided? I already have a loader for uncompressed tga (written in C) and png (through libpng) images, and I can salvage my libjpeg, etc, code from another project. However, using the GLFW provided functions would shrink my codebase and it is appealing to me to make the most of the fewest number of libraries possible. At first I was concerned that GLFW might not be able to handle sRGB textures, but it looks like you can decode the images with GLFW separately and manually load the data into OpenGL.[/QUOTE] They can't deal with file errors or any format other than uncompressed targa. You also don't get any kind of response to such errors (or anything like "file not found") other than GL_FALSE. stb_image on the other hand can load all common file formats, has several different levels of error reporting and is compiled into your project as a single .c file. [editline]27th February 2012[/editline] (Also it plays nicely with PhysFS which is useful c:)
  • Don't. Write. X11. Use SDL or SFML. DO NOT WRITE X11. Use GLUT. FUCKING LISTEN TO ME DON'T FUCK WITH X11. Linux isn't like Win32, you don't have a monolithic blob. X11 creates windows, but you still need to contact the window manager about fullscreen windows, and Xrandr about changing resolutions, and then catch segmentation faults to make sure you reset the resolution or you fuck up the desktop, and you have to make sure you don't grab input or you fuck up window managers, and lots of other shit. Edit: I'm not trying to stress that you shouldn't write X11 code. I'm stressing that you [b]musn't[/b]. Edit 2: If it helps, I'm sure Hitler drafted the X11 specification.
  • Snip first part. :v: Keep the other. Also, world editing is fun. Made a small town. [img]http://dl.dropbox.com/u/99717/NewCity.png[/img] Adding more tiles is also really easy. Whenever I run out of empty tiles in the tileset I just expand it and change a number in the code. And right click on a tile to select that texture.
  • Just finished my Arduino/C# network monitor. It is basically a line of LEDs lighting up as my download speed increases. The C# program allows you to choose which NIC you want to monitor and which serial port the Arduino is connected to. The speed is transmitted in Kb/s which is then mapped by the Arduino to fit the 7 LEDs. It is probably very inaccurate and all that jazz, but it works! [media]http://www.youtube.com/watch?v=W3Td-2NsMgM[/media]
  • Yo, MSVC homies, I gotta problem. More of what I was doing last night: This is really starting to piss me off because this shit makes me run around in circles (sometimes literally, in code speak) and doesn't point at the actual problem. Generally what I see is a manifestation of an issue elsewhere (invalid casting, etc.). [t]http://img836.imageshack.us/img836/2446/gamehl2sb2005debuggingv.png[/t] When debugging, (and I'm sure this is probably a 2005-exclusive issue) I get shit like this. Data looks valid to the code, and doesn't segfault, and this occurs whilst my debugger says it's null or just invalid data, etc. Can anyone explain to me why this occurs, and if it occurs outside of Source projects? Perhaps the pointer it's showing me is to memory that it found earlier on but not an exact representation of the pointer as it is right where my breakpoint is or wherever I'm stepping?
  • hm, I guess I have to retry it. I was pretty sure that % was faster but of course it wouldn't make sense as % does divide the number and that is significantly more work for a CPU than just byte operations but then again I was just too busy drawing my new higher resolution sprites: [IMG]http://dl.dropbox.com/u/22597917/hires.png[/IMG]
  • [QUOTE=amcfaggot;34896749]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[/QUOTE] Haha, I know a lot of programmers are like this (myself included), but one could then argue that you should write the matrix and vector math yourself as well. And, as was stated by someone earlier, X11 is so horrific that no sane Linux developers touch it directly. By the way, Maurice... [img]https://lh3.googleusercontent.com/-Mpm7Ov1fYf0/T0kXZNttPOI/AAAAAAAAVng/YYtIuqNfTKM/w350/Chuck+Norris.gif[/img] Get to work!
  • Remeber a few days ago I asked about mono and SFML speed? well turns out its almost at C++ speed for simple stuff [url]http://www.facepunch.com/threads/1152030?p=34897694&viewfull=1#post34897694[/url] its slow due to my laptop but both programs (C++ and C#) take around te same time to draw and such. Might give some people something to think about :P
  • [QUOTE=icantread49;34895918]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[/QUOTE] "Never" is a little extreme. How about "not any time soon"?