Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 09 Jan 2001
Offline Last Active Today, 07:28 PM

#5076248 Javascript's “Math.sin/Math.cos” and WebGL's “sin/cos” give different...

Posted by MarkS on 08 July 2013 - 06:59 PM

Maybe I am completely off here, but if your desire is for the cubes to be distributed across the surface of a sphere, why not make the inputs to sin and cos lie between -pi and pi? This would make the initial positions lie on a unit sphere and then you can scale them by the radius of the large sphere to get their final positions.

#5076197 Why is hexadecimal used in binary model files?

Posted by MarkS on 08 July 2013 - 01:42 PM

I see now.

These values may be arbitrary, or more likely, they are chosen because they are unlikely/less likely to show up as data values.

I was doing several things at once and typed slowly. Brother Bob beat me to it.ph34r.png

#5076182 Why is hexadecimal used in binary model files?

Posted by MarkS on 08 July 2013 - 12:17 PM

Binary files don't have "chunks". I'm more than a little confused by that. A binary file is a string of bytes that span the length of the file. The only time I've seen "chunks" was in a human readable format.

The term 'chunks' or 'sections' are used to describe different portions of some binary file formats. In your TGA file example, the file format might call the header portion of bytes the "header chunk", and the pixel portion of bytes, the "pixel chunk" (for example).
Some binary file formats even allow their 'chunks' to be put in whatever order, but use code values to identify them so you know how to process them.

I thought of that, but it didn't seem to be what he is asking. I'm more certain that he is looking at a human readable file format with hexadecimal tags.

#5076073 Why is hexadecimal used in binary model files?

Posted by MarkS on 08 July 2013 - 02:43 AM

Binary files don't have "chunks". I'm more than a little confused by that. A binary file is a string of bytes that span the length of the file. The only time I've seen "chunks" was in a human readable format.

Typically a binary file will be formatted to have a header with offsets to the various data and that header will be immediately followed by the file data. What a binary (hexadecimal) string represents to the file loader is entirely defined by the file format.

Here is a binary file. It is a simple 5x5 pixel TGA file. The first 18 bytes are the file header and the image data starts at byte 19 (the 00 immediately following the 08).
00 00 02 00 00 00 00 00 00 00 00 00 05 00 05 00 20 08 00 00 00 FF 00 00 00 FF 00 00 00 FF 00 00 00 FF 00 00 00 FF 00 00 00 FF 00 00 00 FF 00 00 00 FF 00 00 00 FF 00 00 00 FF 00 00 00 FF 00 00 00 FF 00 00 00 FF 00 00 00 FF 00 00 00 FF 00 00 00 FF 00 00 00 FF 00 00 00 FF 00 00 00 FF 00 00 00 FF 00 00 00 FF 00 00 00 FF 00 00 00 FF 00 00 00 FF 00 00 00 FF
The "02" in the header tells the loader that this is an uncompressed, true-color image.
The first "05 00" defines a 16-bit word that tells the loader the width of the image; In this case, 5 pixels.
The second "05 00" defines a 16-bit word that tells the loader the height of the image.
The "20" that follows is 32 in hexadecimal, telling the loader that each pixel in the pixel data is 32-bits (4 bytes).
The "08" is an encoded byte, whose bits tell the loader if the image is flipped as well as the number of alpha channel bits.
The other bytes that I did not explain have special meaning as well, in certain cases, but are unused in this file.
The image data is stored as BGRA (blue, green, red, alpha) and in this case, each pixel has the values "00 00 00 FF".

If you are seeing anything other than hexadecimal in a file, it isn't a binary file.

#5067916 High framerate 2d animations

Posted by MarkS on 06 June 2013 - 04:57 PM

Raña, the manor in which you store the sprite frames has no effect on how smooth your animation is. Whether you store the sprite in a sprite sheet, individual frames or some other format, the smoothness of the animation is a function of the skill of the artist and programmer. If your sprites have a thousand frames of animation, it will ,of course, be smoother than the same sprite with a dozen frames. However, if the sprite engine is based on frame rate and not time, even a thousand frames will not look smooth in many circumstances. You mention 30 FPS. On modern hardware, you should be seeing frame rates well above 100 FPS. I just implemented sprite/tile sheets using OpenGL 3.3 and shaders and I am getting nearly 10,000 FPS drawing a single sprite. If the engine is just NOW reaching 30 FPS, something is wrong with the code or you are attempting to use very old hardware.

I have to admit that I find your question very unclear. What is the issue, exactly? There are few reasons for a sprite to have more than a dozen or so frames per unique animation and even that is a high figure. 

their was a program I used awhile back that did this, but I don't remember it's name off the top of my head, and i'm not on a pc atm.


Tiled does this.

#5061314 "Hacking" a .rom file, is it doable?

Posted by MarkS on 12 May 2013 - 12:16 PM

This is a tricky legal area. You may not be doing anything illegal if all you do is strictly hack the ROM to make it do what you want, but if you copy its contents (which, BTW, is required to hack the ROM), you're breaking the law.

#5055006 Odd frame rate fluctuation when using glm::rotate.

Posted by MarkS on 19 April 2013 - 02:22 PM

I wrote a simple instancing demo for a member here. The demo just creates a cube composed of 512 instances of a cube and the view rotates around this by updating the MVP matrix with glm::rotate. I noticed that the framerate was fluctuating in an almost sinusoidal fashion and this led me to the rotate function. The frame rate goes from a high of around .75 ms/frame to a low of around 1.5 ms/frame. This isn't too bad, but what I find curious, and my main question is, why is this not constant? I tested it and it seems that the frame rate spikes when the angle is 180° and drops to the low point at 0°.


Is this normal? I took a look at the source for glm::rotate, but couldn't find anything wrong. This leads me to believe that I am doing something wrong.


Here is the source:

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
MSG msg;
BOOL done;
gl_win_app app_instance;
RECT bounds;
float angle;
float aspect;
float fov;
GLuint mvp_matrix_loc;
GLuint texture_loc;
GLuint instance_matrix_loc;
GLuint loc_1,loc_2,loc_3,loc_4;
glm::mat4 projection;
glm::mat4 view;
glm::mat4 mvp;
fov = 60.0f;
app_instance.InitializeApp("GL Instance Test");
app_instance.CreateAppWindow("GL Instance Test",WS_EX_APPWINDOW,WS_CAPTION | WS_SYSMENU | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,10,10,1000,1000,false);
done = false;
bounds.bottom += GetSystemMetrics(SM_CYCAPTION) + (GetSystemMetrics(SM_CYFRAME) * 3) + (GetSystemMetrics(SM_CYBORDER) * 3);
bounds.right += (GetSystemMetrics(SM_CXFRAME) * 3) + (GetSystemMetrics(SM_CXBORDER) * 3);
aspect = float(bounds.right) / float(bounds.bottom);
projection = glm::perspective(fov,aspect,0.1f,1000.0f);
view = glm::lookAt(glm::vec3(0.0,0.0,25.0),glm::vec3(0.0,0.0,-25.0),glm::vec3(0,1,0));
shader = LoadShaders("data/instance.vs","data/instance.fs");
mvp_matrix_loc = glGetUniformLocation(shader,"MVP");
texture_loc = glGetUniformLocation(shader,"texture_sampler");
instance_matrix_loc = glGetAttribLocation(shader,"instance_matrix");
loc_1 = instance_matrix_loc + 0;
loc_2 = instance_matrix_loc + 1;
loc_3 = instance_matrix_loc + 2;
loc_4 = instance_matrix_loc + 3;
angle = 0.0f;
if(msg.message == WM_QUIT){
done = true;
mvp = projection * view * glm::rotate(glm::mat4(),angle,glm::vec3(0.0,1.0,1.0));
angle += 0.025f;
if(angle > 360.0f)
angle = 0.0f;
glVertexAttribPointer(loc_1,4,GL_FLOAT,GL_FALSE,sizeof(GLfloat) * 4 * 4,(void*)(0));
glVertexAttribPointer(loc_2,4,GL_FLOAT,GL_FALSE,sizeof(GLfloat) * 4 * 4,(void*)(sizeof(float) * 4));
glVertexAttribPointer(loc_3,4,GL_FLOAT,GL_FALSE,sizeof(GLfloat) * 4 * 4,(void*)(sizeof(float) * 8));
glVertexAttribPointer(loc_4,4,GL_FLOAT,GL_FALSE,sizeof(GLfloat) * 4 * 4,(void*)(sizeof(float) * 12)); 
// Cleanup VBO and shader

#5054352 RECT font_rect

Posted by MarkS on 17 April 2013 - 05:57 PM

Spiro, I'd suggest you take a vacation. Bad/stupid/poorly formatted questions are bound to happen. You're taking this WAY to seriously. You've clearly assisted this member in how to ask questions in an intelligent manner on multiple occasions. At this point, maybe it is time to start reporting the posts? ;)

#5045817 Ah GLM Where is quick reference and function list?

Posted by MarkS on 22 March 2013 - 07:03 PM

I don't think there is a quick reference. The documentation leaves a lot to be desired. The manual is sparse and the API specification (http://glm.g-truc.net/api-0.9.4/index.html) is based on the glm modules, few of which are very descriptive. I find myself spending quite a bit of time digging through the specification and source. Very frustrating.

#5045802 Issue with frustum extraction using glm.

Posted by MarkS on 22 March 2013 - 06:05 PM

I was trying to extract the view frustum from matrices made via glm. I was having no luck with it and finally got it to work by transposing the mvp matrix before extracting the planes. I find this odd as I have done this before using the fixed function pipeline and I have never had to transpose the combined modelview and projection matrix.


This is the frustum extraction code I'm using. I got it from: http://www.crownandcutlass.com/features/technicaldetails/frustum.html , and modified it to use glm. I've gone over the code and I cannot see anything wrong. Any ideas? It works now, but shouldn't, and I am not sure why.


The mvp matrix is defined as:

projection = glm::perspective(fov,aspect,0.1f,1000.0f);
view = glm::lookAt(glm::vec3(0.0,0.0,10.0),glm::vec3(0.0,0.0,-10.0),glm::vec3(0,1,0));
mvp = projection * view * glm::mat4(1.0f);


float InvSqrt(float x)
float xhalf;
int i;
xhalf = 0.5f * x;
i = *(int*)&x;
i = 0x5f3759df - (i >> 1);
x = *(float*)&i;
x = x * (1.5f - xhalf * x * x);
return x;
void frustum::CalculateFrustum(glm::mat4 mvp)
float t;
float m00,m01,m02,m03;
float m10,m11,m12,m13;
float m20,m21,m22,m23;
float m30,m31,m32,m33;
mvp = glm::transpose(mvp);
m00 = mvp[0][0];
m01 = mvp[0][1];
m02 = mvp[0][2];
m03 = mvp[0][3];
m10 = mvp[1][0];
m11 = mvp[1][1];
m12 = mvp[1][2];
m13 = mvp[1][3];
m20 = mvp[2][0];
m21 = mvp[2][1];
m22 = mvp[2][2];
m23 = mvp[2][3];
m30 = mvp[3][0];
m31 = mvp[3][1];
m32 = mvp[3][2];
m33 = mvp[3][3];
planes[0].x = m30 - m00;
planes[0].y = m31 - m01;
planes[0].z = m32 - m02;
planes[0].w = m33 - m03;
t = InvSqrt(planes[0].x * planes[0].x + planes[0].y * planes[0].y + planes[0].z * planes[0].z);
planes[0].x *= t;
planes[0].y *= t;
planes[0].z *= t;
planes[0].w *= t;
planes[1].x = m30 + m00;
planes[1].y = m31 + m01;
planes[1].z = m32 + m02;
planes[1].w = m33 + m03;
t = InvSqrt(planes[1].x * planes[1].x + planes[1].y * planes[1].y + planes[1].z * planes[1].z);
planes[1].x *= t;
planes[1].y *= t;
planes[1].z *= t;
planes[1].w *= t;
planes[2].x = m30 - m10;
planes[2].y = m31 - m11;
planes[2].z = m32 - m12;
planes[2].w = m33 - m13;
t = InvSqrt(planes[2].x * planes[2].x + planes[2].y * planes[2].y + planes[2].z * planes[2].z);
planes[2].x *= t;
planes[2].y *= t;
planes[2].z *= t;
planes[2].w *= t;
planes[3].x = m30 + m10;
planes[3].y = m31 + m11;
planes[3].z = m32 + m12;
planes[3].w = m33 + m13;
t = InvSqrt(planes[3].x * planes[3].x + planes[3].y * planes[3].y + planes[3].z * planes[3].z);
planes[3].x *= t;
planes[3].y *= t;
planes[3].z *= t;
planes[3].w *= t;
planes[4].x = m30 - m20;
planes[4].y = m31 - m21;
planes[4].z = m32 - m22;
planes[4].w = m33 - m23;
t = InvSqrt(planes[4].x * planes[4].x + planes[4].y * planes[4].y + planes[4].z * planes[4].z);
planes[4].x *= t;
planes[4].y *= t;
planes[4].z *= t;
planes[4].w *= t;
planes[5].x = m30 + m20;
planes[5].y = m31 + m21;
planes[5].z = m32 + m22;
planes[5].w = m33 + m23;
t = InvSqrt(planes[5].x * planes[5].x + planes[5].y * planes[5].y + planes[5].z * planes[5].z);
planes[5].x *= t;
planes[5].y *= t;
planes[5].z *= t;
planes[5].w *= t;

#5022773 Is it worth investing time to learn 3D modeling.

Posted by MarkS on 17 January 2013 - 10:53 PM

I tried this and failed. It is easy, as Daaark says, but in the end I just had to admit that I am not an artist. I followed any tutorial I could find, but my mind doesn't work in the manor required. I tend to focus on mechanical details and can model mechanical objects with ease, but cannot get the hang of organic modeling.
I'm not saying that to discourage you, but typically artistic talent appears early in life. If you have it, you know. Try it though. You may find a hidden talent.
My only concern with Blender is that it is open source meaning it evolves very quickly, so what I learn now, many not be the same in a year or 2. Unless, the changes aren't so drastic.  The thing is I am taking courses for graphics, like learning OpenGL and some aspects of how to create a simple game engine

Blender does change frequently, typically every other minor version release. However, this is usually a GUI change or added features. The program has changed significantly since 2.48 (the version I first downloaded), but the techniques still apply.

#5022201 Certain mouse position isn't responding to effect.

Posted by MarkS on 16 January 2013 - 09:28 AM

Buttons 3 and 4 overlap buttons 1 and 2.


See pic...

Attached Thumbnails

  • Buttons.jpg

#5021660 Religons in games

Posted by MarkS on 14 January 2013 - 10:08 PM

I would spend the time to come up with three different religions that have no basis in the real world, like in the Elder Scrolls series. That is unless your game is based in the real world.

#5021596 Calculating matrices and then sending them or sending them and letting the GP...

Posted by MarkS on 14 January 2013 - 04:52 PM

The question is not whether it is faster to calculate the final MVP matrix on the CPU or the GPU, but whether it is faster to calculate it matrix once per model on the CPU or once per vertex on the GPU. But maybe the compiler could, theoretically, precompute the product just before the program is executed, but who knows.



Once per VERTEX?blink.png OK then. Question answered...

#5020358 Does Microsoft purposely slow down OpenGL?

Posted by MarkS on 11 January 2013 - 10:37 AM

What samoth said. Besides, OpenGL is still widely used for scientific visualization and CAD/CAM work. If Microsoft gimped OpenGL, we'd be hearing about it from more sources than a book. Not to mention that someone would have figured a work around by now.