Butabah

Members
  • Content count

    28
  • Joined

  • Last visited

Community Reputation

100 Neutral

About Butabah

  • Rank
    Member
  1. I have made a 2D OpenGL engine. It does 2D stuff. Renders 2D objects of any size (albeit square), collision detection, rendering text, texture using, UI capabilities (click events, key events, a UI bar with buttons) I've made this, and it looks like I've done nothing. It's 2000~ lines of C++ code, and it feels like nothing. What could I do to snazz it up? Any suggestions? These objects are fully movable, rotatable, scalable. I have a manager managing all the updating, rendering, and input. I wrote a math library too of vectors and matrix math. The design of the code is pure OO, making it easy to implement new objects, UI buttons, and etc. Like I said, I don't want to give up on it and move to XNA or something else, because I've worked on this since July... I just look at it and my mind goes blank P.S. I'm a programmer, not a Graphic Artist, so my textures are very laughable, but I'm trying!
  2. [quote name='YogurtEmperor' timestamp='1314417852' post='4854308'] Dynamically generating shaders is one option. Since the lights will be on for the duration of the render, you won’t be incurring extra shader swaps and should have little overhead aside from the number of shader permutations created. If you don’t want this overhead or you don’t have an efficient way to search for the shader to use based on what system states (including combinations of lights that are enabled), you can keep track of your light states within your client and when it comes time to render you can sort them so that all directional lights come first, followed by all point lights, followed by all spot lights. You would not be using the GLSL built-in glogal uniforms for this; just make your own set of uniforms. In the shader you have 3 totals. One for each type of light. You also have all of the light information stored in uniform arrays such that the first X are the properties for directional lights, the next X are points and the next X are spots. You can then do a for loop for each light type, sharing the index between loops. For example, if you wanted to support a maximum of 8 lights at a time, you could store up to 8 uniform light vectors: [code]uniform vec4 g_vLightVecs[8];[/code] As well as the number of directional, point, and spot lights. [code]uniform int g_iDirLights; uniform int g_iPointLights; uniform int g_iSpotLights;[/code] Then loop over each light type in order: [code]for ( int i = 0; i < g_iDirLights; i++ ) { // Directional light computations. // g_vLightVecs[i] = current directional light vector. } for ( int i = 0; i < g_iPointLights; i++ ) { // Point light computations. // g_vLightVecs[i+g_iDirLights] = current point light position. } for ( int i = 0; i < g_iPointLights; i++ ) { // Spot light computations. // g_vLightVecs[i+g_iDirLights+g_iPointLights] = current spot light position. }[/code] Note that you can optimize the use of [b]i+g_iDirLights+g_iPointLights[/b] etc., I am just writing it this way for clarity. The reason for making 3 loops is that performing if/else checks inside loops is extremely slow. You want a way to “just know” that you are dealing with a directional, point, or spot light. L. Spiro [/quote] Cool! This really helped, thanks!
  3. What would be the best way to go about handling dynamic lights within GLSL? By dynamic I mean lights that can fade away and come in at any time, the user creates them as they wish. I was thinking about dynamically making shaders, but that sounds waaay too over the top for something like this.
  4. [quote name='Trienco' timestamp='1313988550' post='4852124'] [quote name='Butabah' timestamp='1313976195' post='4852080'] Should I tell the UI to move with the camera or is there a way I can keep it statically in the same spot? [/quote] How are you drawing your stuff anyway? Blitting, OpenGL, DirectX, some existing engine? The obvious question would be: what makes you think that everything needs to be drawn using the same "camera"? [/quote] Using OpenGL with my own Camera (float[16]) class. I guess I never thought of it that way. I have a uniform buffer object that I update to do most of the matrix work such as camera to clip and camera to world matrices. I guess the obvious choice would be to not have the UI on the same camera system as the other objects. Thanks!
  5. So, let's pretend I have a UI with a health bar in the top left corner in a 2D game. If I were to move the camera, the UI itself stays in the same position it was earlier. Should I tell the UI to move with the camera or is there a way I can keep it statically in the same spot?
  6. Starting a custom physics engine.

    Thanks for all your feedback! It's been really useful!
  7. [quote name='RDragon1' timestamp='1310615903' post='4835120'] Yeah, loop through the squares and see if the mouse overlaps. Keep track of the nearest one. At the end of the loop, you know what was clicked on. Sounds good. You have to define what 'better' means. There's lots of opposing ways to make something 'better', and making it better in one direction almost always means making it worse in some other direction. If you want it "better" in terms of minimizing the number of squares you have to test against the mouse, there's several things you can do. One way is to split the screen into a coarse grid and have a list of squares per tile. Then you get the tile the mouse overlaps and only loop over those squares. You could organize the squares into more complicated structures like quadtrees, etc. to minimize the number of intersection tests. There's other ways you could want it to be 'better'. Maybe you want the algorithm to be more paralellizable so you can run the algorithm across multiple cpu cores. In that case I would split the squares into batches, and hand each batch off to a core. Each core will find the 'best' match out of their set. Then take that reduced number of squares and find the best out of that. Maybe you want it 'better' in terms of memory usage (minimized). Maybe that means you store the rectangles in a compressed format in memory. That may end up having a profound impact on the speed at which you can iterate over and do the intersection tests, but it will take up less memory. [/quote] Thanks for your input! I'll be doing some research and see which methods suit my needs the best, right now the iteration works, but I'm afraid of memory drops once there's alot of items on screen.
  8. Hi there, I've been taking my time Game Programming, jumping here and there. A topic I haven't dealt with is physics. What's a good starting point for physics? Any good reference material? Examples with OpenGL would be awesome, but I'm already asking a lot. I know I could google this all, but you guys are always so insightful.
  9. I have squares just littered around my screen, and would like to be able to use my mouse to click on a certain one. My plan was to iterate through a list of all currently visible objects (done in C++) and match the X and Y coordinates (can't click on one behind another) Does anyone have a better way that they do this, or point me in the direction of some reading that I may do?
  10. OpenGL Best openGL resource

    Avoid deprecated functionality. One thing that will make everything easier is if you try and create a framework as you move along, i.e. I created an object with hard code, Then I created code to make the object for me, Now I can have hundreds of objects on screen. I created a shader\program object with hard code, Then I created code to do all the compiling, linking, for me. Now it's much easier for me to make shaders. Just START SLOW, Don't move on until you understand something.
  11. [quote name='kauna' timestamp='1310579817' post='4834928'] [color="#1C2837"][size="2"][color="#000000"]posVector [/color][color="#666600"]+=[/color][color="#000000"] vec4[/color][color="#666600"]([/color][color="#000000"]worldCoords[/color][color="#666600"],[/color] [color="#006666"]1.0[/color][color="#666600"]);[/color][/size][/color] I don't know about your z-coordinate, but it seems that by adding the vector above to the [font="CourierNew, monospace"][size="2"]posVector, you'll end up having w-component with value 2.0f. Which isn't maybe what you are after right?.[/size][/font] [font="CourierNew, monospace"] [/font] [font="CourierNew, monospace"][size="2"]Cheers![/size][/font] [/quote] Hmm, you're right, let me try that out. Hey man, you were right! that fixed it! [img]http://i.imgur.com/3g1t1.png[/img]
  12. Hey guys, I have an issue with my shader, where I am able to translate in the X, Y axis, but not in the Z. Here is my shader: [code] #version 330 layout(location = 0) in vec3 vVerts; layout(location = 2) in vec2 vTex; uniform mat4 modelviewMatrix; uniform mat4 projectionMatrix; uniform vec3 worldCoords; smooth out vec2 vTexCoords; void main() { mat4 modelviewProjectionMatrix = projectionMatrix * modelviewMatrix; vec4 posVector = vec4(vVerts, 1.0); posVector += vec4(worldCoords, 1.0); vec4 pos = modelviewProjectionMatrix * posVector; vTexCoords = vTex; gl_Position = pos; } [/code] Obviously with worldCoords it should be able to update the Z axis, but it simply doesn't move at all. Any ideas?
  13. Unusual FreeGlut error

    [quote name='vicer1234' timestamp='1310475359' post='4834269'] there is no errors when compiled but when i try to run it the command line splashes and disappears in a way it crashes The command line shows a message [size="3"][b] FREEGLUT ERROR : Function <glutdDisplayFunc> called without first calling 'glutInit'. [/b]But as you can see i have called glutInit function [b] [/b]I tried in google but did not get any proper solution for it... What is the reason for this BUG???? All suggestions are welcome [/size] [/quote] What is the purpose of [code] main_window = glutCreateWindow("Hello"); [/code] I ran your code in VS2010 with no errors. Here is my code: [code] #include <gl\freeglut.h> #pragma comment(lib, "freeglut.lib") void Reshape(int w, int h) { } void Display() { } int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitWindowSize(1024, 768); glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE|GLUT_STENCIL|GLUT_DEPTH); glutCreateWindow("Hello"); glutDisplayFunc( Display ); glutReshapeFunc( Reshape ); glutMainLoop(); return EXIT_SUCCESS; } [/code] The pragma directive simply links the library.
  14. [quote name='Brother Bob' timestamp='1310417578' post='4833983'] The standard in old OpenGL are are column major, so it's your second option. But the more general, and actually correct answer is; it depends on what convention you use. When you use shaders and your own matrix computations, [i]you[/i] decide the order or everything. [/quote] Okay cool, thank you very much!
  15. Hi there, I'm working on some rotations and translations, and would like to know, is the OpenGL matrix structure m[0] m[1] m[2] m[3] or m[0] m[2] m[1] m[3]