1. Post #601
    Gold Member
    esalaka's Avatar
    July 2007
    10,248 Posts
    Not really.

    Edited:

    One thing you could do is something like new.Wall and give new a metatable __index that makes it construct shit. Somehow.
    Reply With Quote Edit / Delete Linux Finland Show Events

  2. Post #602
    Richy19's Avatar
    May 2010
    5,411 Posts
    Not really.

    Edited:

    One thing you could do is something like new.Wall and give new a metatable __index that makes it construct shit. Somehow.
    Well its more a case of atm I only know how to do lua_getglobal(L, "Width");

    But if I were to have say 20 different wall objects how would I differentiate between them, or how would I get them?
    I mean having a table of say:
    Code:
    wall{
    int posX
    int posY
    int width
    int height
    color col
    ...
    }
    And then having to specify each parameter individually isnt a problem
    Reply With Quote Edit / Delete Linux United Kingdom Show Events

  3. Post #603
    Sickle's Avatar
    November 2009
    6,600 Posts
    boolean inArray = false;
    		
    		for (int m = 0; m < array.length; m++)
    		{
    			
    			if (array[m] == target)
    			{
    				
    				int index = m;
    				System.out.println(target + " is at index " + index + " in the array.");
    				
    			}
    			if (inArray = false)
    			{
    				System.out.println(target + " is not in the array!");
    			}
    			
    		}
    

    Hey guys, why does my if (inArray = false) never execute, even when I have the target?

    (There's more code if you guys need it)
    Reply With Quote Edit / Delete Windows 7 South Africa Show Events

  4. Post #604
    Richy19's Avatar
    May 2010
    5,411 Posts
    boolean inArray = false;
    		
    		for (int m = 0; m < array.length; m++)
    		{
    			
    			if (array[m] == target)
    			{
    				
    				int index = m;
    				System.out.println(target + " is at index " + index + " in the array.");
    				
    			}
    			if (inArray = false)
    			{
    				System.out.println(target + " is not in the array!");
    			}
    			
    		}
    

    Hey guys, why does my if (inArray = false) never execute, even when I have the target?

    (There's more code if you guys need it)
    you need double =
    change it to (inArray == false)
    Reply With Quote Edit / Delete Linux United Kingdom Show Events Agree Agree x 1Friendly Friendly x 1 (list)

  5. Post #605
    Sickle's Avatar
    November 2009
    6,600 Posts
    you need double =
    change it to (inArray == false)
    Ooohhh, thanks, man!

    Oh wow, no matter what I do, the thing outputs, 'x is not in the array!'

    target = (int)((Math.random() * 100) + 1);
            System.out.println("The target is " + target);
             
            boolean inArray = false;
             
            for (int m = 0; m < array.length; m++)
            {
                 
                if (array[m] == target)
                {
                     
                    int index = m;
                    inArray = true;
                    System.out.println(target + " is at index " + index + " in the array.");
                     
                }
                else
                {
                	inArray = false;
                }
            }
            if (inArray == false)
            {
                System.out.println(target + " is not in the array!");
            }
    

    Anyone know what I'm doing wrong with my if statements?
    Reply With Quote Edit / Delete Windows 7 South Africa Show Events

  6. Post #606
    Richy19's Avatar
    May 2010
    5,411 Posts
    I want to have a mini console in my game, where I can output stuff or input stuff, but I want to also display all the cout stuff in it, now I managed to find out how to cnage the cout to be a different fstream to for example write it to a file, but I was wondering how can I access what is stored in the cout's stream?

    my idea was to say during the init stages or update stages have stuff output to cout, then have the console class read all the stream of the cout in the update stage and just print it to screen
    Is this possible?
    Reply With Quote Edit / Delete Linux United Kingdom Show Events Agree Agree x 1 (list)

  7. Post #607
    Grimpunch Games
    TM Gmod's Avatar
    May 2005
    524 Posts
    I want to have a mini console in my game, where I can output stuff or input stuff, but I want to also display all the cout stuff in it, now I managed to find out how to cnage the cout to be a different fstream to for example write it to a file, but I was wondering how can I access what is stored in the cout's stream?

    my idea was to say during the init stages or update stages have stuff output to cout, then have the console class read all the stream of the cout in the update stage and just print it to screen
    Is this possible?
    I also need to know this! :D
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  8. Post #608
    Icedshot's Avatar
    April 2010
    2,361 Posts
    How do i go about turning a floating point number into an integer? And i dont mean by rounding, i mean by scaling the floating point number so that float_max and float_min map to int_max and int_min.

    Unfortunately opencl only allows for an integer depth buffer due to stupid atomic functions. So i need to convert my floating point numbers to integers while retaining precision, and then back again

    Currently im just times-ing them by a large constant, but i get the feeling there is a proper way to do it out there somewhere. Or at the very least, a much better way of doing it

    Edit:

    Or, if anyone has any solutions as to how to work an integer depth buffer, i'd love to here it
    Reply With Quote Edit / Delete Windows Vista United Kingdom Show Events

  9. Post #609
    Gold Member

    March 2005
    3,028 Posts
    How do i go about turning a floating point number into an integer? And i dont mean by rounding, i mean by scaling the floating point number so that float_max and float_min map to int_max and int_min.
    That's not going to work well for you at all.
    You might be able to get something out of it if you map logarithmically.
    Like:
    int y = sign(x) * (float)INT_MAX * (128.0 + log2(abs(x))) / 256.0

    ...and whatever the reverse process of that is.

    Edit:
    The reverse process is:
    float x = sign(x) * exp2(256.0 * (float)abs(x) / (float)INT_MAX - 128.0)

    Unfortunately opencl only allows for an integer depth buffer due to stupid atomic functions. So i need to convert my floating point numbers to integers while retaining precision, and then back again
    Don't try to map the entire range of values. That's a bad idea. Choose a 'near plane' and a 'far plane' and scale that range to the range of integers. Look at how OpenGL handles projection. It uses integer depth buffers for most things.

    Currently im just times-ing them by a large constant, but i get the feeling there is a proper way to do it out there somewhere. Or at the very least, a much better way of doing it
    http://www.songho.ca/opengl/gl_projectionmatrix.html
    And after you've got depth in the [-1, 1] range, it's trivial to remap to the range of integers.
    Reply With Quote Edit / Delete Windows 7 Show Events

  10. Post #610
    Gold Member
    ThePuska's Avatar
    October 2005
    3,450 Posts
    I want to have a mini console in my game, where I can output stuff or input stuff, but I want to also display all the cout stuff in it, now I managed to find out how to cnage the cout to be a different fstream to for example write it to a file, but I was wondering how can I access what is stored in the cout's stream?

    my idea was to say during the init stages or update stages have stuff output to cout, then have the console class read all the stream of the cout in the update stage and just print it to screen
    Is this possible?
    I have no experience doing specifically what you're trying to do, and this is C rather than C++, but one could use a (temporary) log file and print/read from it. Or an obstack or some equivalent, or a custom stream which primarily writes into memory and periodically and upon termination into a log file. If you were using glibc all this would be easy with cookies: fopencookie().
    Reply With Quote Edit / Delete Windows 7 Finland Show Events

  11. Post #611
    Arsonide's Avatar
    June 2008
    233 Posts
    Okay I'm going to ask this here, because it seems appropriate. I'm working on a project, and I need to modify someone else's code slightly. A little, minor change. The only problem is that he used Boost, and Boost refuses to properly install or something. I tried installing it from scratch, and I tried using BoostPro. I don't see what I can be doing wrong as I followed a guide, and BoostPro has like three checkboxes that you fill in appropriate to your IDE. I'm using VS9/2008.

    When I try to compile, Boost explodes with all sorts of errors, here's an excerpt: http://pastebin.com/qJdQ8w2X

    I really want to continue working on my project. Does anybody have any idea what is going on? I've asked in Boost's IRC channel, but it's surprisingly idle and the only answers I've gotten are "You did it wrong. Do it again." I've done it four times now, tried compiling from scratch following a guide, and BoostPro has like three checkboxes - there's no way to screw it up.

    EDIT: I updated Visual Studio and downgraded Boost to 1.42. Seems to work now.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  12. Post #612
    T3hGamerDK's Avatar
    January 2011
    2,551 Posts
    Uhh.. Why are you building Boost with Visual Studio? You're supposed to be using the Boost.Build system, by running 'bootstrap.bat' and following the readme.
    Did you even read it??
    Reply With Quote Edit / Delete Mac Denmark Show Events

  13. Post #613
    Dennab
    September 2011
    3,417 Posts
    I'm trying to code a nuclear strike simulator in Visual Basic.
    I got the required info for simulating a strike on the city of oulu (148500 people, density 102.11/km2) but I don't know how to move on from there (we started coding this year).

    Code:
    Dim Oulu As Single = 148500
    Dim Y As Double = 2.5
    The Y is the multiplier for thermal, blast, and radiation per 2,5 kiloton warhead.
    Code:
    r_thermal = Y^0.41*constant_th
    r_blast = Y^0.33*constant_bl
    r_radiation = Y^0.19*constant_rad
    I am starting with the effects of the strike during the strike and immediately after, only calculating the casualty rate.
    Reply With Quote Edit / Delete Windows 7 Finland Show Events

  14. Post #614
    Icedshot's Avatar
    April 2010
    2,361 Posts
    That's not going to work well for you at all.
    You might be able to get something out of it if you map logarithmically.
    Like:
    int y = sign(x) * (float)INT_MAX * (128.0 + log2(abs(x))) / 256.0

    ...and whatever the reverse process of that is.

    Edit:
    The reverse process is:
    float x = sign(x) * exp2(256.0 * (float)abs(x) / (float)INT_MAX - 128.0)


    Don't try to map the entire range of values. That's a bad idea. Choose a 'near plane' and a 'far plane' and scale that range to the range of integers. Look at how OpenGL handles projection. It uses integer depth buffers for most things.


    http://www.songho.ca/opengl/gl_projectionmatrix.html
    And after you've got depth in the [-1, 1] range, it's trivial to remap to the range of integers.
    I see

    I ended up using a logarithmic depth buffer to scale between -1 and 1 and *sing by int_max, thanks
    Reply With Quote Edit / Delete Windows Vista United Kingdom Show Events Friendly Friendly x 1 (list)

  15. Post #615
    boy i sure do love it when my title doesnt fit
    LuaChobo's Avatar
    December 2009
    6,499 Posts
    -wait fuck im dumb god-

    Well i got my mod to launch through Visual Studio fine, but the actual client just crashes with no error.
    so idk
    Reply With Quote Edit / Delete Windows 7 Australia Show Events

  16. Post #616
    Casual Bananas
    E X C L's Avatar
    February 2011
    1,716 Posts
    Has anyone else ever experienced blue screens after compiling SFML in Visual Studio?
    I can use it just fine in XCode but when I tried to set it up for windows it gives a blue screen after it's done compiling.
    Reply With Quote Edit / Delete Mac Netherlands Show Events Disagree Disagree x 1 (list)

  17. Post #617
    Arsonide's Avatar
    June 2008
    233 Posts
    Uhh.. Why are you building Boost with Visual Studio? You're supposed to be using the Boost.Build system, by running 'bootstrap.bat' and following the readme.
    Did you even read it??
    I did build it with the Boost build system. I meant when I try to compile something that uses Boost.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  18. Post #618
    no-named's Avatar
    July 2008
    740 Posts
    Ooohhh, thanks, man!

    Oh wow, no matter what I do, the thing outputs, 'x is not in the array!'


    target = (int)((Math.random() * 100) + 1); System.out.println("The target is " + target); boolean inArray = false; for (int m = 0; m < array.length; m++) { if (array[m] == target) { int index = m; inArray = true; System.out.println(target + " is at index " + index + " in the array."); } else { inArray = false; } } if (inArray == false) { System.out.println(target + " is not in the array!"); }

    Anyone know what I'm doing wrong with my if statements?

    It looks to me like the else
                else
                {
                    inArray = false;
                }
    is not needed. When it's there, if there are any elements after the target that is not equal to the target, inArray is set to false. If it is unessecery to look through the whole array when the target is found just once, you can also break; the loop in the if (array[m] == target).
    Reply With Quote Edit / Delete Windows 7 Denmark Show Events Friendly Friendly x 1 (list)

  19. Post #619
    Gold Member
    Over-Run's Avatar
    January 2006
    3,133 Posts
    I have to make a design document for 3 games I am making as a college project.
    The games are Connect Four, Snakes and Ladders and Checkers.
    I have Connect Four and Snakes and ladders so far, could you guys tell me if it looks okay or if I should change anything?

    http://pastebin.com/iEgxyi9r
    Reply With Quote Edit / Delete Windows 7 Ireland Show Events

  20. Post #620
    Eudoxia's Avatar
    July 2009
    6,009 Posts
    Yeah and I prefer to learn from a book if it's related to programming, I don't know why but I just find it easier.
    I always love learning from books, but all the programming books I've picked up were sort of eehhh.

    I always end up reading function references and source code :(
    Reply With Quote Edit / Delete Linux Uruguay Show Events Agree Agree x 1 (list)

  21. Post #621
    Zwolf11's Avatar
    July 2009
    605 Posts
    So for my current project in C Programming class we need to make the fastest and most memory efficient program we can for following buy and sell orders of stocks. This project is a continuation of the past two projects that we've been working on and I already have a working program using a hash map for data storage up and running. The question is now that we can use any data structure to hold the data and the purpose of the project is to try and run the fastest, which data structure should I use?

    In the project there is many add, delete, and edit commands, so the data structure should be set up so that I can easily find whichever order I need by id #. I also need to be able to access the highest buy and lowest sell priced order every n commands (could either keep a sorted structure at all times or keep an unordered structure and only sort it after n commands). Currently I have a hash map that contains several linked lists of order nodes sorted by id. Each node contains the order id, if the order is to buy or sell, quantity of the order, and price. I also have two linked lists that keep track of the orders in terms of buy/sell prices (the head of the linked list being the current lowest and the tail being the current highest).

    I was considering using two heaps (one for buy and one for sell) where the root for the buy heap was the highest price and the root for the sell heap was the lowest price, but then that means that whenever I want to delete an order (when a delete command is given, only the id is supplied) then I would have to search both trees to find it. Any ideas, Facepunch?
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  22. Post #622
    Gold Member
    thrawn2787's Avatar
    April 2007
    8,707 Posts
    How many stocks will you need to keep track of? Hash might be the fastest, and not sorting the buckets might help (you take a bit of a hit when finding the highest / lowest / searching by id, but sorting takes time. Question is which takes more?). If the buckets aren't huge then a linear search through the bucket won't hurt much. You could always just have pointers to the min / max and when adding new / editing stocks see if they are the new min / max, that way you don't even have to search for them. But then if you delete one you have to search for the new min / max.

    You could do some sort of a priority queue where stocks that are queried most often get higher priority (and lose priority after a certain amount of time) and just do linear searches on that.

    Also you mention you have a hash table and linked lists, how many structures can you use (I don't mean you used linked lists to make a hash map but that you said you had the stocks stored in several structures)? Also if you know the max id # then you can make a perfect hash and get rid of buckets. It could waste a little bit of memory if you aren't filling it all up but accessing would be faster. Pros and cons to everything I guess.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  23. Post #623
    Zwolf11's Avatar
    July 2009
    605 Posts
    How many stocks will you need to keep track of? Hash might be the fastest, and not sorting the buckets might help (you take a bit of a hit when finding the highest / lowest / searching by id, but sorting takes time. Question is which takes more?). If the buckets aren't huge then a linear search through the bucket won't hurt much. You could always just have pointers to the min / max and when adding new / editing stocks see if they are the new min / max, that way you don't even have to search for them. But then if you delete one you have to search for the new min / max.

    You could do some sort of a priority queue where stocks that are queried most often get higher priority (and lose priority after a certain amount of time) and just do linear searches on that.

    Also you mention you have a hash table and linked lists, how many structures can you use (I don't mean you used linked lists to make a hash map but that you said you had the stocks stored in several structures)? Also if you know the max id # then you can make a perfect hash and get rid of buckets. It could waste a little bit of memory if you aren't filling it all up but accessing would be faster. Pros and cons to everything I guess.
    The input file has orders for many different stocks but a symbol is given in the command line arguments and I only have to keep track of the one stock and ignore the orders about all the others. It's not really likely that one order will be queried more often so that'd be a waste of processing time. Also, the max id is unknown. They can be any number that can fit in an unsigned int.

    Here's a pdf showing how I have my data sorted: http://piazza-uploads.s3-website-us-...orted_list.pdf

    The solid lines are how the orders are stored in the hash map and the dotted lines show the buy/sell list and how they are connecting the nodes contained within the hash map. The image only shows one buy/sell list, but I actually have 2, buy and sell. No order is in both the buy and sell list because orders are either being bought or sold. Therefore, every order is in the hash map sorted by id and also in either the buy or sell list.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Informative Informative x 1 (list)

  24. Post #624
    Gold Member
    thrawn2787's Avatar
    April 2007
    8,707 Posts
    Oh that's really neat, never thought to have a list inside a hash like that. That looks pretty fast as is.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  25. Post #625
    Gold Member
    nemmises5's Avatar
    May 2010
    1,926 Posts
    is it necessary to be good at math to program? I can do the basics, addition, Subtraction, multiplication, division, and basic geometry and algebra, but after that I lose it.

    Edited:

    specifically Python for blender animations and stuff.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Funny Funny x 2 (list)

  26. Post #626
    T3hGamerDK's Avatar
    January 2011
    2,551 Posts
    is it necessary to be good at math to program? I can do the basics, addition, Subtraction, multiplication, division, and basic geometry and algebra, but after that I lose it.

    Edited:

    specifically Python for blender animations and stuff.
    For games, you might want to learn some trigonometry too, but no, you don't actually need to know more than this.
    Reply With Quote Edit / Delete Mac Denmark Show Events Disagree Disagree x 1Agree Agree x 1 (list)

  27. Post #627
    Gold Member
    Over-Run's Avatar
    January 2006
    3,133 Posts
    I have to make a design document for 3 games I am making as a college project.
    The games are Connect Four, Snakes and Ladders and Checkers.
    I have Connect Four and Snakes and ladders so far, could you guys tell me if it looks okay or if I should change anything?

    http://pastebin.com/iEgxyi9r
    Reply With Quote Edit / Delete Windows 7 Ireland Show Events

  28. Post #628
    Richy19's Avatar
    May 2010
    5,411 Posts
    Im trying to get my head around movement in a fps style movement system.

    basically in my shitty point skills
    [imghttp://i.imgur.com/XbO26.png[/img]

    so in code:
    //View = glm::mat4(1.0);
        View = glm::lookAt(
        glm::vec3(0, 5, 3), // the position of your camera, in world space
        glm::vec3(0, 0, 0),   // where you want to look at, in world space
        glm::vec3(0, 1, 0)        // probably glm::vec3(0,1,0), but (0,-1,0) would make you looking upside-down, which can be great too
        );
    

    im guessing when you look straight its simple, say you move left, you just subtract say 10*delta to the x of the position and of the lookingAtPosition

    but what if your not looking straight?

    and when you move the mouse the position your looking at changes, but it would have to change in a circular motion, i think I get how it would be done with trig. I just have to first do the X value and then the Y right?
    Reply With Quote Edit / Delete Linux United Kingdom Show Events

  29. Post #629
    Gold Member
    Naelstrom's Avatar
    June 2010
    2,758 Posts
    Im trying to get my head around movement in a fps style movement system.

    basically in my shitty point skills
    [imghttp://i.imgur.com/XbO26.png[/img]

    so in code:
    //View = glm::mat4(1.0);
        View = glm::lookAt(
        glm::vec3(0, 5, 3), // the position of your camera, in world space
        glm::vec3(0, 0, 0),   // where you want to look at, in world space
        glm::vec3(0, 1, 0)        // probably glm::vec3(0,1,0), but (0,-1,0) would make you looking upside-down, which can be great too
        );
    

    im guessing when you look straight its simple, say you move left, you just subtract say 10*delta to the x of the position and of the lookingAtPosition

    but what if your not looking straight?

    and when you move the mouse the position your looking at changes, but it would have to change in a circular motion, i think I get how it would be done with trig. I just have to first do the X value and then the Y right?
    Get the angles you're looking in and use trig to move him in that direction (X += sin(yaw); Y += cos(yaw)). I've noticed you're in Linux and not online in steam.

    Get steam working in Linux and I'll answer your questions more directly, if you have gmail I can chat with you at naelstrof@gmail.com to help you get steam working.
    Reply With Quote Edit / Delete Linux United States Show Events

  30. Post #630
    calzoneman's Avatar
    February 2008
    460 Posts
    is it necessary to be good at math to program? I can do the basics, addition, Subtraction, multiplication, division, and basic geometry and algebra, but after that I lose it.

    Edited:

    specifically Python for blender animations and stuff.
    As with anything it depends on the complexity. For 2D stuff basic Algebra, Geometry, and Trigonometry will be fine. For 3D you'll need to understand more complex trigonometry and matrix Algebra.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  31. Post #631
    Gold Member
    conman420's Avatar
    January 2007
    1,795 Posts
    What is a fast way to figure out if a sprite is on screen or not? I want a fast way of culling non-visible entities from the draw queue, was going to just do AABB checks for each sprite but that sounds really inefficient.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  32. Post #632
    Richy19's Avatar
    May 2010
    5,411 Posts
    if( !screenRect.contains( sprite.rect ) )
    Reply With Quote Edit / Delete Linux United Kingdom Show Events Friendly Friendly x 1 (list)

  33. Post #633
    Gold Member
    Larikang's Avatar
    November 2005
    2,589 Posts
    There's something about derived classes in C++ that I'm not understanding.

    #include <iostream>
    using namespace std;
    
    class Base
    {
    public:
    	Base() { cerr << "Created base " << this << endl; }
    	virtual ~Base() { cerr << "Destroyed base " << this << endl; }
    };
    
    class Derived : public Base
    {
    public:
    	Derived() { cerr << "Created derived " << this << endl; }
    	Derived(const Base & b) { cerr << "Copied derived " << this << endl; }
    	~Derived() { cerr << "Destroyed derived " << this << endl; }
    };
    
    int main()
    {
    	Derived x;
    	Derived y (x);
    	return EXIT_SUCCESS;
    }

    Displays
    Code:
    Created base 0x1234
    Created derived 0x1234
    Destroyed derived 0x5678
    Destroyed base 0x5678
    Destroyed derived 0x1234
    Destroyed base 0x1234
    That is to say, Derived y (x) calls only the implicit Base copy constructor, skipping the one I defined entirely. Why is that? I figured it would interpret x as a Base, and find the matching constructor declaration, but instead it seems to interpret both x and y as Base.

    The reason I'm trying to do this is because I want several classes all deriving from the same abstract base class, but all able to be constructed using any of the others - without needing to code a specific constructor for each class. Using the clone pattern works, but that's almost as tedious because then I need to define a clone method for every derived class.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  34. Post #634
    Gold Member
    ShaunOfTheLive's Avatar
    November 2007
    9,905 Posts
    That is to say, Derived y (x) calls only the implicit Base copy constructor, skipping the one I defined entirely. Why is that? I figured it would interpret x as a Base, and find the matching constructor declaration, but instead it seems to interpret both x and y as Base.
    No, it's interpreting both x and y as Derived, which means it's not going to call your custom constructor that takes a Base instead of a Derived. But I think if you cast what you're passing to Base, it'll work. Try this:

    Derived y ((Base)x);
    

    (Or maybe I have no idea what I'm talking about; I haven't dealt with the complexities of the C++ type system in a while)
    Reply With Quote Edit / Delete Windows 7 Canada Show Events Friendly Friendly x 1 (list)

  35. Post #635
    Richy19's Avatar
    May 2010
    5,411 Posts
    Im trying to create a flat 256*256 verticie field, so I have the following:

    #define pointCount 768
    
    GLfloat g_vertex_buffer_data[pointCount * pointCount];
        
    
    
    
        int x = 0;
        for(int y = 0; y < (pointCount)/3.0f;y++)
        {
                g_vertex_buffer_data[(int)(y*(pointCount/3.0f) + x )] = (float)x;
                g_vertex_buffer_data[(int)(y*(pointCount/3.0f) + x + 1 )] = 0.0f;
                g_vertex_buffer_data[(int)(y*(pointCount/3.0f) + x + 2 )] = (float)y;
                x+=3;
                if(x > (pointCount/3.0f)) x = 0;
        }
    
    
    
    // Generate 1 buffer, put the resulting identifier in vertexbuffer
        glGenBuffers(1, &vertexbuffer);
    
    // The following commands will talk about our 'vertexbuffer' buffer
        glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
    
    // Give our vertices to OpenGL.
        glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);
    
    //...////////////////////////////////////
    
    // 1rst attribute buffer : vertices
        glEnableVertexAttribArray(positionID);
        glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
        glVertexAttribPointer(
            positionID,                  // attribute 0. No particular reason for 0, but must match the layout in the shader.
            3,                  // size
            GL_FLOAT,           // type
            GL_FALSE,           // normalized?
            0,                  // stride
            (void*)0            // array buffer offset
        );
    
    
        // Draw the triangle !
        glDrawArrays(GL_TRIANGLES, 0, 130050); // Starting from vertex 0; 3 vertices total -> 1 triangle
    
    

    Can anyone see if there is anything wrong with this? Im guessing its with the actuall filling of the array as when drawing it, it isnt flat it looks more like a corner, as in it bends in half
    Reply With Quote Edit / Delete Linux United Kingdom Show Events

  36. Post #636
    Gold Member
    Larikang's Avatar
    November 2005
    2,589 Posts
    No, it's interpreting both x and y as Derived, which means it's not going to call your custom constructor that takes a Base instead of a Derived. But I think if you cast what you're passing to Base, it'll work. Try this:

    Derived y ((Base)x);
    

    (Or maybe I have no idea what I'm talking about; I haven't dealt with the complexities of the C++ type system in a while)
    Ugh, that worked! I can't believe I didn't try that after being stuck for hours...
    Reply With Quote Edit / Delete Linux United States Show Events Winner Winner x 1 (list)

  37. Post #637
    Gold Member
    Hypershadsy's Avatar
    February 2008
    2,423 Posts
    What is a fast way to figure out if a sprite is on screen or not? I want a fast way of culling non-visible entities from the draw queue, was going to just do AABB checks for each sprite but that sounds really inefficient.
    Are you counting completely transparent pixels?
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  38. Post #638
    Gold Member

    March 2005
    3,028 Posts
    Im trying to create a flat 256*256 verticie field, so I have the following:

    #define pointCount 768
    
    GLfloat g_vertex_buffer_data[pointCount * pointCount];
        
    
    
    
        int x = 0;
        for(int y = 0; y < (pointCount)/3.0f;y++)
        {
                g_vertex_buffer_data[(int)(y*(pointCount/3.0f) + x )] = (float)x;
                g_vertex_buffer_data[(int)(y*(pointCount/3.0f) + x + 1 )] = 0.0f;
                g_vertex_buffer_data[(int)(y*(pointCount/3.0f) + x + 2 )] = (float)y;
                x+=3;
                if(x > (pointCount/3.0f)) x = 0;
        }
    
    
    
    // Generate 1 buffer, put the resulting identifier in vertexbuffer
        glGenBuffers(1, &vertexbuffer);
    
    // The following commands will talk about our 'vertexbuffer' buffer
        glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
    
    // Give our vertices to OpenGL.
        glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);
    
    //...////////////////////////////////////
    
    // 1rst attribute buffer : vertices
        glEnableVertexAttribArray(positionID);
        glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
        glVertexAttribPointer(
            positionID,                  // attribute 0. No particular reason for 0, but must match the layout in the shader.
            3,                  // size
            GL_FLOAT,           // type
            GL_FALSE,           // normalized?
            0,                  // stride
            (void*)0            // array buffer offset
        );
    
    
        // Draw the triangle !
        glDrawArrays(GL_TRIANGLES, 0, 130050); // Starting from vertex 0; 3 vertices total -> 1 triangle
    
    

    Can anyone see if there is anything wrong with this? Im guessing its with the actuall filling of the array as when drawing it, it isnt flat it looks more like a corner, as in it bends in half
    1. You appear to have an obsession with using floating-point numbers as divisors in inappropriate places.
    2. Your buffer dimensions are off, and you're iterating over the values incorrectly. It's 256 * 256 * 3, not 768 * 768. You should be doing either:
    for (int y = 0; y < 256; y++) {
      for (int x = 0; x < 256; x++) {
        i = y * 256 + x;
        point[i*3 + 0] = (float)x;
        point[i*3 + 1] = (float)y;
        point[i*3 + 2] = 0.0f;
      }
    }
    
    or

    for (int i = 0; i < 256*256; i++) {
      x = i % 256;
      y = i / 256;
      point[i*3 + 0] = (float)x;
      point[i*3 + 1] = (float)y;
      point[i*3 + 2] = 0.0f;
    }
    
    Reply With Quote Edit / Delete Windows 7 Show Events Useful Useful x 1Informative Informative x 1 (list)

  39. Post #639
    Casual Bananas
    E X C L's Avatar
    February 2011
    1,716 Posts
    -snip- thanks
    Reply With Quote Edit / Delete Windows 7 Netherlands Show Events Funny Funny x 1 (list)

  40. Post #640
    Gold Member
    conman420's Avatar
    January 2007
    1,795 Posts
    Are you counting completely transparent pixels?
    Yes, it is just a rough estimate whether or not the sprite should draw.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events