Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 18 Feb 2008
Offline Last Active Jul 12 2014 04:42 PM

Topics I've Started

I need help with matrices

09 April 2014 - 08:03 AM

Hey guys,

I would greatly appreciate any help you can offer me. I'm writing a big Entity/Sprite/Model/Rendering system and I am having the hardest time understanding how to use matrices properly. I guess my main questions is: how can I use only a single matrix per object to define where it is located, how it is rotated, and how it is scaled? Since matrix multiplication is cumulative, I have come to the conclusion that I have no choice but to store a (Vector3D) position, (Quaternion) rotation, and (Vector3D) scale, and then re-calculate the matrix (for rendering) each frame from these values. This seems.... cumbersome and ugly. Is there some way to simply have a Matrix for each object and modify it directly when I call SetPosition(), RotateX(), etc.? I'm not that great with Matrix manipulation, so maybe this is no-brainer, but I can't seem to find any direct answer to this no matter where I search.


Side note: This isn't meant to sound rude at all, but please don't suggest that I use SDL or some matrix library. I get that a lot, but I want to make this myself. I just need some help in the right direction. Believe me, I've tried learning this myself, but I learn by example, so reading books explaining matrices just doesn't make it click for me.


Thanks in advance!

Help getting started with GLSL?

15 January 2012 - 07:35 PM

I'm trying to get a very simple vertex shader running but nothing seems to be happening. The shader loads, compiles, and links successfully - no errors. When I try to use it however, nothing renders. Here is my shader code:

void main(void)
	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

As far as I know, the above code should just render the vertex like usual, correct?
Here is my drawing code in the application itself:

	glColor3f(0.0f, 1.0f, 0.0f);
	glVertex3f(0.0f, -1.0f, -1.0f);
	glVertex3f(0.0f, -1.0f,  1.0f);
	glVertex3f(0.0f,  1.0f,  1.0f);
	glVertex3f(0.0f,  1.0f, -1.0f);

If I comment out 'glUseProgram(programObject)' the quad renders just fine. Otherwise, nothing is rendered at all from what I can see anyways.

I know this is simple but I swear I've Googled the hell out of it and can't figure out what I'm doing wrong. Any help would be much appreciated. Thanks.

EDIT: Figured it out. Apparently if you don't specify a color in the shader source, it draws the vertex black. So I wasn't seeing it on my black background. D'oh!

How to capture raw mouse input in X11?

16 January 2011 - 09:56 PM

For the Windows version of my game engine, I'm using WM_INPUT and registering the mouse device directly to get the most precise movements. Anyone know how I would go about doing this in X11 (for Linux)? I've searched Google about as thoroughly as I can, but finding good documentation for X11 is next to impossible.

[C++] Weird segmentation fault

05 January 2011 - 12:13 PM

Getting a weird crash here. My game engine compiles fine and runs fine, until I exit, where I get a segmentation fault, or more specifically, this:

*** glibc detected *** ./bin/engine: corrupted double-linked list: 0x092f8df8 ***
*** glibc detected *** ./bin/engine: corrupted double-linked list: 0x092f9eb8 ***
Segmentation fault

This only happens on Linux. Windows doesn't seem to complain about any of this. The piece of code where it happens is here:
	void Graphics::DeleteTexture(GLuint _id) {
textures[_id] = NULL; // <-------

This is a function that gets called in my Texture class's destructor. "textures" is a vector of Texture pointers in my Graphics class that keeps track of all Texture objects declared, for purposes of freeing up memory when texture data goes unused and falls into limbo. This function always succeeds during normal execution, but fails when the program is closing and is destructing all of my remaining Texture objects.

I know the first thing you will ask is that I post more code, but seriously, nothing else affects this line of code. My game engine is not multi-threaded (yet) and if I comment out this piece of code, everything works fine (except of course unused texture data remains in memory!). I have tried multiple things with this one line of code, including checking that the pointer is valid before setting it to NULL, and using "cout" to show the value of the pointer before and after the operation (first value always shows as valid, followed by a 0 as expected, but then the error shows afterwards).

Also, the above error only occurs when one Texture object is being destroyed at exit. If there is more than one, I get this instead:

*** glibc detected *** ./bin/engine: free(): corrupted unsorted chunks: 0x09151000 ***
Segmentation fault

Anyone have a clue what's happening here?

What is the point of Makefiles?

26 November 2010 - 02:01 PM

In pretty much any source package I've downloaded, there is a Makefile. I've looked at a few and they're big, bloated, and ugly to look at. I couldn't imagine writing one. Is there some advantage to them over compiling straight from the command line? The way I do it is this:

My project directory has a "bin" and "src" folder and a compile script for each operating system the source code supports. The compile script for Linux, for instance, would be something like this:
g++ -o ./bin/executable -lLibrary1 -lLibrary2 `ls ./src/*.cpp`

That simple 1-line script will compile every .cpp in the src folder with the specified libraries and spit out the executable into the bin folder. I don't really understand how a Makefile would be needed.

Any insight?