Jump to content

  • Log In with Google      Sign In   
  • Create Account

Brother Bob

Member Since 26 Nov 2001
Online Last Active Today, 07:29 PM

#5011061 Applying a perspective matrix

Posted by Brother Bob on 15 December 2012 - 04:39 PM

I don't know, why don't you try and see?

I'm not saying that is the only problem, just one I saw. I could see another potential problem in that only the far side of the cube remains, and with back face culling, you won't see the back of the cube (which would be viewed with the inside towards the viewpoint) assuming the winding order of all faces are consistent. A better idea than adjusting the near clip plane is to simply move the cube inside the view volume instead. Move it 1 or 2 units into the scene so that the Z-range becomes, say, 1 to 1.5 instead.

#5011048 Applying a perspective matrix

Posted by Brother Bob on 15 December 2012 - 04:10 PM

The cube extends from 0 to 0.5 along all axes, including the Z-axis, and the near clip plane of the projection matrix is 0.5. As expected, the cube is clipped entirely because it is outside the view volume.

#5011034 Using std::vector to load data to VBO

Posted by Brother Bob on 15 December 2012 - 02:57 PM

When drawing, you're binding the color buffer object but setting the vertex pointer. Sounds from your description though that you are much better of drawing pixel rectangle with glDrawPixels instead of drawing the individual pixels as points.

#5010379 Could someone give me feedback on my algorithm?

Posted by Brother Bob on 13 December 2012 - 05:10 PM

First step is to obtain the 2-dimensional coordinate of a square. For example, if k is what you call the current square is a 1-dimensional sequential index (for example you number the squares sequentially along a row, and column by column), then you can obtain the (x,y) coordinate as x=k%8 and y=k/8.

Once you have a 2-dimensional coordinate into the checker board, you can color it according to:
if(x%2 == y%2)
    red square
    white square

#5009094 New Class made -> error LNK2019: unresolved external symbol

Posted by Brother Bob on 10 December 2012 - 09:43 AM

But is that standard c++ to treat point p(float(x), float(y)) as function declaration?

It is, unfortunately.

#5009041 My VBO world system. Any thoughts?

Posted by Brother Bob on 10 December 2012 - 05:12 AM

the bit at the end is just a sample usage not necessarily the best one. And as for start3D and end3D being restrictive I found that in my game it resulted in less opengl calls if I enabled everything right off the bat and then disabled the ones that I did in the rare case that I didn't need all of them not need for example I have a drawSkybox function which disables tangents and normals.

It may work now, but it will definitely bite you later on because it's going to be a nightmare to maintain and get right, and especially get optimal as you aim for. You may very well get to the point where the disabling-and-enabling-when-done approach will cost you just as much as enabling-and-disabling-when-done approach. What you effectively end up with is a global enable state, and then local disable-on-demand calls.

You're aiming for a global optimum, so you're gonna need a global solution. For example, some state manager that doesn't re-enable things that are enabled already, or sets pointers that are already set. You can only achieve local optimum with local calls. For example, consider that you draw your sky box that, as you say, doesn't have tangents and normals, so you disable tangents and normals before drawing it, and then re-enable it again. That may be the optimum way to handle it since you only need to disable a few states.

Then you want to draw a small GUI or something that doesn't have tangents and normals either. So you do the same thing again; you disable them, draw the GUI and enable them before exiting; again, locally the optimum way to do it. But the net effect are four redundant calls; two do enabble two states and then two more to disable them again. Local optimum, but not global optimum.

As for my draw function do you propose that It looks like this, removing the pointers:

void Chunk::draw()		  
glUniform1i(texture_location, 0);
glBindTexture(GL_TEXTURE_2D, bitmap);
glUniform1i(normal_texture_location, 1);
glBindTexture(GL_TEXTURE_2D, normap);
glUniform1i(height_texture_loc, 2);
glBindTexture(GL_TEXTURE_2D, heightmap);

glBindBuffer(GL_ARRAY_BUFFER, tBuffer); //texcoords
glBindBuffer(GL_ARRAY_BUFFER, vBuffer); //positions
glBindBuffer(GL_ARRAY_BUFFER, nBuffer); //normals
glBindBuffer(GL_ARRAY_BUFFER, tanBuffer); //tangents
glDrawArrays(GL_TRIANGLES, 0, numtriangles*3);

because I tried that and it broke the function.

Kaptein already addressed it, but I said that the pointers in the update function, not the draw function, served no purpose.

BTW this code is just for the internals of my game not for a library or anything I don't really care if it makes sense but rather that it's as fast as possible.

When your code base grows, you will forget about the details about an increasing amount of your very own code, and it will become unfamiliar to you. Design is not only for other's sake, but for your own as well.

#5008934 My VBO world system. Any thoughts?

Posted by Brother Bob on 09 December 2012 - 07:06 PM

Why do you have allocate and upload as two separate functions if they are supposed to be called together? Are there times where you expect to allocate the buffers but not upload any data?

What is the purpose of allocating empty buffers the size of a single float in the allocate function? If you actually indent to pre-allocate the whole buffer, you should allocate a buffer large enough to store the actual data you put into it later and then use glBufferSubData instead to upload the content to an existing buffer; glBufferData will discard the old buffer and create a new one and your pre-allocated buffer was of no use.

You set the vertex attribute pointers in both the upload and the draw functions. Setting the pointers in the upload function serves no purpose since you're not using the binding points anywhere except in the draw function, and the draw function already set the attribute pointers.

You don't have to enable the buffers to upload data to them. Your calls to start3D and stop3D around the upload calls have no purpose.

I find your setup very limiting because you have generic functions to enable vertex attribute arrays, but they force a specific vertex array layout: any vertex array you draw must have a position, a normal, a texture coordinate and a generic attribute array; no more, no less. Either you intend to use that function for the Chunk class only, in which case it is named way too generically named, or you should use a more flexible vertex array system that doesn't force a specific vertex attribute set, but rather enables what is in use. If you intend to only use the functions for the Chunk class, then put the two helper functions in the chunk class to show that they are for the Chunk class specifically and nothing else.

The redundant state changes I can see are, except for setting the attribute pointers in the upload function, could be the result of the very limited test bed you have in the while loop. The while loop calls end3D and then calls start3D again in the next iteration. Unless "// do other stuff" actually depends on end3D being called, the observable state changes in OpenGL could be that you disable and then re-enable some states immediately after each other.

#5007750 Read/Write binary

Posted by Brother Bob on 06 December 2012 - 07:32 AM

vertices is the pointer to the buffer returned by new, but &vertices is a pointer to the value of the vertices pointer. You want to read into the buffer, not overwrite the pointer value returned by new, so drop the &.

#5007453 what does negative waveform actually do?

Posted by Brother Bob on 05 December 2012 - 11:19 AM

this is OK.but what if your just generate abs of your sine wave?

well,i did.and....it still sounds like sine wave sound....

Do you mean that the absolute value of the sine wave sounds like a sine wave, or that it sounds like the original sine wave?

Both are wrong though. Taking the absolute value of a sine wave introduces over-tones since the sine wave is no longer pure. What you get is a collection of multiple sine waves of which one, the fundamental frequency which is twice the original frequency, is the most dominant. If you take the absolute value of a 500 Hz sine wave, you get a fundamental frequency of 1000 Hz, as well as harmonics which are multiples of 1000 Hz.

The negative part of a sine wave is just as much part of the sine wave as the positive part of it. If you alter it, you no longer have a sine wave.

#5007359 Casting Arguments in Function Pointers

Posted by Brother Bob on 05 December 2012 - 05:27 AM

Ignoring what is strictly correct, because it can be quite tricky when it comes to casting and I'm not sure what is actually correct or not, but 1 is likely to behave as you expect, and 2 is likely to break when the size of a pointer is difference from the size of an integer.

But 2 wouldn't even work as you expect anyway, because qsort passes pointers to the elements to be compares, but your predicate assumes the elements are passed by value (or at leas that is what I assume you mean by taking the integers by value).

My advice is to never cast a function pointer. It comes with so much more than a value that has to be reinterpreted. For example, parameter type information and parameters being read from the stack, and if the caller passes one type and the callee reads another type from the stack, then you may have screwed up the stack. So, never cast a function pointer, but let the caller pass the expected data and reinterpret it inside the called function instead. That means that all your qsort predicates should return a int and take two void-pointers, and then you cast the void-pointers inside the function.

#5007275 Confused by Pointers (Beginner's Script):

Posted by Brother Bob on 04 December 2012 - 08:03 PM

What is it you find confusing about the two lines? One assigns pointers, the other assigns the values pointed to by the pointers. The line p1=p2 simply means that the two pointers point to the same address, while *p2=*p1 assigns the values pointed to by the two pointers.

#5006338 Is gluPerspective deprecated?

Posted by Brother Bob on 02 December 2012 - 12:38 PM

And what do you expect to happen when you call it, even if there is no error reported? The function operates on the current matrix stack, but there is no such thing in a core context.

#5005799 How to create a 2.1 context on recent Nvidia hardware?

Posted by Brother Bob on 30 November 2012 - 01:26 PM

There is no way to request a specific version before 3.0, but it doesn't matter anyway since nothing changes for new versions.

#5005026 Trying to solve mathematical problem using programing skills

Posted by Brother Bob on 28 November 2012 - 12:43 PM

You're accumulating multiples of 15 twice since those numbers are divisible by both 3 and 5. I'm not going to provide a solution though, but let you think about it.

#5004555 Separate Functions to Compress From Memory and From a File

Posted by Brother Bob on 27 November 2012 - 10:30 AM

You could implement the compression from memory buffer only, and have the file-variant load from file into memory and pass it to the compression function. Depending on if you can do compression of partial buffers or not, you either load the whole file and compress it or load part and compress it in parts if you don't want to load the entire file at once.