Friday, February 11, 2011

Programmers Anonymous notes, 0

 Sec Narf requested a start of a project:
Can we mess around with putting 'windows'(like buttons, text fields, or forms of output) in a window? We could do something like write a random number generator where you press a button, a dice rolling sound plays, and your result is displayed in the window. After that we could make maybe it more complicated...
How does one play sounds in our current C environment? I found a nice example code/program,, that implements a button (as a mesh icon with OpenGL) and plays a sound, a .wav file. It is only useful on a Windows (Win32 only?) platform, as it uses the Beep() or PlaySound() function that is found in the Windows API (declared in window.h):

        Beep(1000, 40);
        PlaySound("MySound.wav", NULL, SND_FILENAME);

On other hardware platforms, there are probably corresponding functions. This example program, with a screenshot, is from this set of OpenGL programs and code.

Jacob's comic blog, 256. Minimalist existentialism.

Sec Narf's Tumblr blog, DuctTapeCreations. It is not important to know how to factor polynomials, though it might improve your algebra grade. It is very important to know that polynomials can sometimes be factored.

From Irreduceable polynomials (Wikipedia):
It is helpful to compare irreducible polynomials to prime numbers: prime numbers (together with the corresponding negative numbers of equal modulus) are the irreducible integers. They exhibit many of the general properties of the concept of 'irreducibility' that equally apply to irreducible polynomials, such as the essentially unique factorization into prime or irreducible factors.

Griffin's newest c = c + 1 comic, "Star System". I like its meta-legend. I wish there was a facility for hyperlinking items in strips.

The Wormworld Saga, Daniele Lieske. Don't miss the descriptions of how he does his visual art and stories in his blog archives.

Critical gaming blog
    Emergence you can see
We have come to a point where how we talk about video games is insufficient in expressing how we feel and think about them. With each year comes increasingly complex games, yet we are still, for the most part, writing and talking about games on a shallow consumer level.

It is time to start thinking and writing critically about games. However, before we can do this, we must approach gaming from a critical mode or mindset. To do this, we must first understand of how the different parts of a game work together (game design). Unfortunately, many of the people who have experience in this area spend their time making video games. Beyond this, the body of knowledge that does exist is scattered at best. For this reason, it is hard for a thorough understanding of game design and critique to become widespread.

From Digital physics (Wikipedia):
"It always bothers me that, according to the laws as we understand them today, it takes a computing machine an infinite number of logical operations to figure out what goes on in no matter how tiny a region of space, and no matter how tiny a region of time. How can all that be going on in that tiny space? Why should it take an infinite amount of logic to figure out what one tiny piece of space/time is going to do?"
So I have often made the hypothesis that ultimately physics will not require a mathematical statement, that in the end the machinery will be revealed, and the laws will turn out to be simple, like the checker board with all its apparent complexities. But this speculation is of the same nature as those other people make—'I like it,' 'I don't like it'—and it is not good to be prejudiced about these things"   Richard Feynman

We're currently working with OpenGL libraries, and the dinoshade.c code is a very good OpenGL example:
Example for PC game developers to show how to combine texturing, reflections, and projected shadows all in real-time with OpenGL. Robust reflections use stenciling. Robust projected shadows use both stenciling and polygon offset.

GLfloat is defined in gl.h with the statement:
typedef float           GLfloat;        /* single precision float */
So it is just another name for float type, which is itself represented by 32-bits on a 32-bit operating system.

Declaration and explicit assignment of an array in C/C++, with 2 dimensions holding a list of coordinate pairs, where each coordinate is of type GLfloat:
GLfloat body[][2] = { {a,b}, {c,d} ... }
In C this array "body" is not of type GLfloat, but is a pointer to the memory location of the first element of the array.

Implicitly an array is passed by reference (as a pointer), not by value (as all the array elements). Only the pointer is needed, not a copy of every element of the array. But most functions will need to know the size of the array, so a second argument is needed because the array size is "out of scope" within the function:
extrudeSolidFromPolygon( body, sizeof(body), bodyWidth, ...);

  We can use pointer arithmetic to trim the first 2 coordinate pairs, if we know the size of each element of the array:
// a pointer to the 5th element of the array  
body + 4   

// size (in memory) of the  array without the
// first 4 elements, or 2 coordinate pairs

// as arguments in a function call
extrudeSolidFromPolygon( body + 4, sizeof(body)-4*sizeof(GLfloat), ... );
This references the array elements starting with the fifth, through the end of the array. The syntax looks strange (and it is not obvious) if you are not used to thinking about array names as a pointer to memory.

No comments:

Post a Comment