# StasB

Members

51

144 Neutral

• Rank
Member
1. ## Random Gradients for Perlin Noise

Hi! My question is pretty simple: What are some good ways to generate random N-dimensional gradients for Perlin noise?
2. ## OpenGL Projecting Textures

I didn't know texture coordinates had Z and W components. I think I get it now. I guess I should do some more reading about how OpenGL works. Thanks, guys.
3. ## OpenGL Projecting Textures

I don't understand. Getting the texture coordinate for a world vertex involves a division by the distance from the projector's near plane. That's a non-linear function. =S
4. ## OpenGL Projecting Textures

I need to project some textures to simulate sprite shadows but I can't wrap my head around how it's done in OpenGL. From what I understand, for each vertex of the projection surface, I need to calculate the coordinates on the projected texture and let OpenGL interpolate them automatically. This doesn't quite make sense to me because the interpolated function isn't even linear since it's basically a perspective projection. Pic related: [img]http://i.imgur.com/TFQ3F.png[/img] I'll be glad if someone could explain. Thanks. =)

6. ## OpenGL Wrapping OpenGL Calls

[quote name='Yours3!f' timestamp='1331305753' post='4920683'] well, while wrapping the whole api is possible, in my opinion its rather pointless. You might want to write a state manager as suggested, but I think that you shouldn't wrap everything, but rather certain functionality (mesh loading, texture loading, shader loading etc.) which enables you to use OGL without making a single error, because the wrapper class takes care of it. for ex. you could say that the current buffer stored would be: struct buffer_state { GLuint buffer; GLenum target; } current_buffer_state; and you could implement a function that checks if the current buffer bound is the one you pass to it, and in that case it wouldn't call the OGL function: void my_bind_buffer(GLenum target, GLuint buffer) { if(current_buffer_state.buffer != buffer || current_buffer_state.target != target) //check the current state { if(glIsBuffer(buffer)) //check if it is really a buffer { glBindBuffer(target, buffer); } } } or something like this... you might want to check out pixellight for a whole api wrap example. when your app starts up you could just simply query the current gl state with glGet* to initialize your states [/quote] Basically, here's my problem: I need to write my own versions of the OGL state-setter functions I care for that check for redundant state changes. Some of those functions take a parameter that specifies which state to change, like glBindBuffer. Ideally, if I write a glBindBuffer wrapper, it better act like the original, accept a target parameter and handle it correctly. How do I do that without manually writing special code for every type of target?
7. ## OpenGL Wrapping OpenGL Calls

[quote name='Murdocki' timestamp='1331302390' post='4920669'] Yes it's possible, it's called object orientation. You create classes with specific responsibilities. This will add a very tiny mini overhead but it's more than worth it. The trick is to pull your classes to an as high as possible level of abstraction without creating overly complex class responsibilities. For example, who sais you're using VBOs, maybe you've just got some vertex data that needs to be rendered however the implementation sees fit. To counter the state changes you might end up with a state manager which only changes state if it is required. [/quote] I thought it was clear from my OP that object orientation is what I'm trying to achieve. I'm just worried about the performance penalties from redundant state changes. I just want a thin and convenient layer on top of plain OpenGL to ease up the task of writing a higher-level graphics engine. I thought about making a state manager, but I'm not sure how to go about it. How would you go about wrapping "void glBindBuffer( GLenum target, GLuint buffer)", for example?
8. ## OpenGL Wrapping OpenGL Calls

I'm tired of my code being littered with verbose GL calls. I've been wondering if there's any way to wrap things up in small classes without a serious loss of performance and generality. For example, if I want to have a VBO class, every member function that does something with a VBO needs to make sure it is bound first. If I want to render it, I need to make sure all the client states (e.g. glEnableClientState(GL_VERTEX_ARRAY)) and pointers (e.g. glVertexPointer(...)) are set up correctly. The only robust way to do that is to set all relevant global state in every member function call, even when it's unnecessary. Wouldn't all this state-changing cause some serious performance issues?
9. ## bullet trajectory in 3D space, finding velocity to hit target

It doesn't matter what _you_ are naturally inclined to consider. It's not a language-specific detail. It's the basic precedence rules of math, which, naturally, any sane programming language obeys, be it is C-like or not. This has nothing to do with memorizing programming language rules. Your post makes no valid points or any sense. Sometimes, there's some benefit from using brackets merely for clarity. Not in this trivial case. End of story.
10. ## bullet trajectory in 3D space, finding velocity to hit target

@allMadeFromCode: I'm confused... Isn't there a whole bunch of possible angle\velocity combinations to hit a target? @Fenrisulvur: Quote:It's not at all good practice to rely upon the order of operations imposed by a language when implementing these things. It's less readable since people typically end up having to consult some sort of reference to remind themselves, and it's a great way to introduce non-trivial bugs into your code. I see no real problem with relying upon the operator precedence defined by _math_. Last time I had to consult a reference to remind myself about it was in elementary school. By your logic, why stop at turning A / B * C into (A / B) * C? Maybe we should also turn A + B + C into (A + B) + C? =|
11. ## Overlap collision tests between hierarchical objects

Performance-wise, you have nothing to lose by using hierarchies... Unless, of course, your characters are more likely to overlap than not. The question is whether you have anything to gain. Personally, I kind of doubt it. Anyway, you know what they say: premature optimization is the root of all evil. Go get something working. If it's not fast enough, then start thinking about it.
12. ## Convex collision

First of all, what exactly are you interested in? Collision detection (checking whether two polygons collide), or collision response (separating two colliding polygons and making them bounce off each other)? In any case, your reference has little to do with polygon collision... You might want to read this: Separating Axis Theorem Explained
13. ## Algorithm for placing stars on a grid to form a galaxy

Well, your algorithm is definitely faster than what I originally had in mind, but consider what happens when you randomly pick a small star that has some big stars around it that are "illegal"... They will be erased and their space will be wasted, even though you could fit smaller "legal" stars in there. You could run out of space and end up with less stars than you wanted, even though you have clearly visible empty spaces where starts could fit... At least in theory...
14. ## Algorithm for placing stars on a grid to form a galaxy

Not sure what you mean, but glad I could help. =P
15. ## Algorithm for placing stars on a grid to form a galaxy

Completely fill the grid with random stars. Randomly pick N of them. This algorithm depends only on the number of cells. The simplest and cheapest solution.