1. Post #1
    NovembrDobby's Avatar
    April 2007
    1,157 Posts
    Need help with something? Post it here!

    V3
    V2
    V1
    Reply With Quote Edit / Delete Windows XP United Kingdom Show Events Friendly Friendly x 4 (list)

  2. Post #2
    Exosel's Avatar
    February 2010
    1,760 Posts
    How would I go about making a sprite rotate depending on the location of the mouse? Could someone give me a general idea on how to do it.(I'm using SFML and C++)
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  3. Post #3
    Gold Member
    robmaister12's Avatar
    January 2008
    4,969 Posts
    What type of rotation are you talking about? Do you want the angle to change as you move the mouse in along the X axis or do you want to have the sprite point towards the cursor?
    Reply With Quote Edit / Delete Windows 7 United States Show Events Friendly Friendly x 1 (list)

  4. Post #4
    Exosel's Avatar
    February 2010
    1,760 Posts
    What type of rotation are you talking about? Do you want the angle to change as you move the mouse in along the X axis or do you want to have the sprite point towards the cursor?
    I want the sprite to point towards the cursor.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  5. Post #5
    I gave enough money to buy a soda.
    Funley's Avatar
    May 2010
    1,426 Posts
    I want the sprite to point towards the cursor.
    Use Atan2. In pseudocde:
    Code:
    rotation = Atan2(mouse.Y - object.Y, mouse.X - object.Y)
    If that doesnt work, try flipping the arguments as in mouse.X - object.X and mouse.Y - object.Y. The returned angle will be in radians.
    Reply With Quote Edit / Delete Windows 7 Finland Show Events Agree Agree x 1Friendly Friendly x 1 (list)

  6. Post #6
    Gold Member
    robmaister12's Avatar
    January 2008
    4,969 Posts
    Additionally, here's something I recently learned relating to atan2:

    Code:
    angleBetween = atan2(cross(v1, v2), dot(v1, v2))
    can also be done with 2d vectors by using the perpendicular dot product:

    Code:
    angleBetween = atan2(perpDot(v1, v2), dot(v1, v2))
    Edited:

    where v1 and v2 are 3d vectors in the first code example, and 2d vectors in the second.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Informative Informative x 1Programming King Programming King x 1 (list)

  7. Post #7
    Gold Member
    raBBish's Avatar
    March 2007
    2,667 Posts
    Additionally, here's something I recently learned relating to atan2:

    Code:
    angleBetween = atan2(cross(v1, v2), dot(v1, v2))
    can also be done with 2d vectors by using the perpendicular dot product:

    Code:
    angleBetween = atan2(perpDot(v1, v2), dot(v1, v2))
    Edited:

    where v1 and v2 are 3d vectors in the first code example, and 2d vectors in the second.
    Isn't that the same as acos(dot(v1, v2))?

    vvvvvv Completely forgot about that.
    Reply With Quote Edit / Delete Windows 7 Finland Show Events

  8. Post #8
    Gold Member
    robmaister12's Avatar
    January 2008
    4,969 Posts
    Isn't that the same as acos(dot(v1, v2))?
    Yes, but atan2 is prefered over acos because of inaccuracies when nearing 0 and pi. Also atan2 gives the direction of rotation from v1 to v2 where acos does not, because the range of atan2 is [-pi, pi) where the range of acos is (0, pi)
    Reply With Quote Edit / Delete Windows 7 United States Show Events Informative Informative x 1 (list)

  9. Post #9
    flayne's Avatar
    January 2011
    1,628 Posts
    I'm getting strange compiler errors with VC++ :'(

    http://www.facepunch.com/threads/1152160

    Resolved thanks guys! :D
    Reply With Quote Edit / Delete Windows Vista United States Show Events

  10. Post #10
    Exosel's Avatar
    February 2010
    1,760 Posts
    Use Atan2. In pseudocde:
    Code:
    rotation = Atan2(mouse.Y - object.Y, mouse.X - object.Y)
    If that doesnt work, try flipping the arguments as in mouse.X - object.X and mouse.Y - object.Y. The returned angle will be in radians.
    I did this but it still doesn't work properly:

    		MouseRad = atan2(sf::Mouse::GetPosition().x - shipSpr.GetPosition().x, sf::Mouse::GetPosition().y - shipSpr.GetPosition().y);
    		MouseDeg = (MouseRad) * (180/PI);
    		
    		shipSpr.SetOrigin(shipSpr.GetPosition().x/2, shipSpr.GetPosition().y/2);
    		shipSpr.Rotate(MouseDeg);
    
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  11. Post #11
    Nigey Nige's Avatar
    June 2010
    1,341 Posts
    Quoting from last thread because Garry closed it on me, the bellend.

    Nigey Nige posted:
    I'm making a top-down 2D exploration game (using Slick), and I want to continuously reveal more of the map through fog as the player explores. I can't think of a good way to do this. Ideas?
    reevezy67 posted:
    I know one of the more common/efficient methods is called shadow casting and I would actually know how to do this too.
    Shadow casting sounds interesting, but I want the map to slowly turn from grey fog into explored regions and stay that way once uncovered. Is that the best way of doing it?
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  12. Post #12
    Chuushajou's Avatar
    June 2010
    904 Posts
    Ever had one of those days where everything is going perfect- and you get loads done? Well mine's just gone to shit. The problem is that Google Maps isn't unloading(?) when another scene is being selected- thus giving the end result of this;


    Reply With Quote Edit / Delete Windows Vista United Kingdom Show Events Friendly Friendly x 1 (list)

  13. Post #13
    flayne's Avatar
    January 2011
    1,628 Posts
    I need help with VC++ 2010 express. I need to set up my additional include directories from an environment variable so my entire team can use the same directories. How would I do this?
    Reply With Quote Edit / Delete Windows Vista United States Show Events

  14. Post #14
    Clops with bisousbisous daily <3
    Mr. Smartass's Avatar
    December 2010
    9,188 Posts
    There's an issue with what I assume is either my installation of XNA, or visual studio. Whenever I save a project, the content folder for said project instantly thinks it's corrupt, even though it can still access the content within it. This prevents me from adding any new resources, and is very frustrating. What can I do to fix this?

    The content folder is doing this:




    Help would really be appreciated, I've been locked from programming for almost two weeks because of this.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  15. Post #15
    sim642's Avatar
    July 2010
    1,039 Posts
    I did this but it still doesn't work properly:

    		MouseRad = atan2(sf::Mouse::GetPosition().x - shipSpr.GetPosition().x, sf::Mouse::GetPosition().y - shipSpr.GetPosition().y);
    		MouseDeg = (MouseRad) * (180/PI);
    		
    		shipSpr.SetOrigin(shipSpr.GetPosition().x/2, shipSpr.GetPosition().y/2);
    		shipSpr.Rotate(MouseDeg);
    
    .Rotate() does it relative to current rotation if you want to set rotation you should use .SetRotation() instead.
    Reply With Quote Edit / Delete Windows Vista Estonia Show Events

  16. Post #16
    Gold Member
    Lord Ned's Avatar
    April 2006
    3,702 Posts
    There's an issue with what I assume is either my installation of XNA, or visual studio. Whenever I save a project, the content folder for said project instantly thinks it's corrupt, even though it can still access the content within it. This prevents me from adding any new resources, and is very frustrating. What can I do to fix this?

    The content folder is doing this:




    Help would really be appreciated, I've been locked from programming for almost two weeks because of this.
    Reinstall XNA/Visual Studio?

    Or see if you can edit the content-project manually. It won't be fun but it might work.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  17. Post #17
    NovembrDobby's Avatar
    April 2007
    1,157 Posts
    I did this but it still doesn't work properly
    You got the X and Y backwards in atan2, it seems weird but it's Y then X.

    Try this:

    Code:
    MouseRad = atan2(sf::Mouse::GetPosition().y - shipSpr.GetPosition().y, sf::Mouse::GetPosition().x - shipSpr.GetPosition().x);
    Reply With Quote Edit / Delete Windows XP United Kingdom Show Events

  18. Post #18
    Clops with bisousbisous daily <3
    Mr. Smartass's Avatar
    December 2010
    9,188 Posts
    Reinstall XNA/Visual Studio?

    Or see if you can edit the content-project manually. It won't be fun but it might work.
    Edit it how so? As in edit the actual folder's contents?
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  19. Post #19
    Exosel's Avatar
    February 2010
    1,760 Posts
    You got the X and Y backwards in atan2, it seems weird but it's Y then X.

    Try this:

    Code:
    MouseRad = atan2(sf::Mouse::GetPosition().y - shipSpr.GetPosition().y, sf::Mouse::GetPosition().x - shipSpr.GetPosition().x);
    Okay, I changed my code to this but it seems that the sprite is not rotating on its own center even though I made the sprite's origin in the center of the sprite:

    MouseRad = atan2(sf::Mouse::GetPosition().y - shipSpr.GetPosition().y, sf::Mouse::GetPosition().x - shipSpr.GetPosition().x);
    MouseDeg = (MouseRad) * (180/PI);
    		
    shipSpr.SetOrigin(shipSpr.GetPosition().x/2, shipSpr.GetPosition().y/2);
    shipSpr.SetRotation(MouseDeg);
    
    
    

    I think I found the problem, I'm setting the origin to the position where the sprite is, not on the sprite.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  20. Post #20
    Gold Member
    Lord Ned's Avatar
    April 2006
    3,702 Posts
    Edit it how so? As in edit the actual folder's contents?
    The Reference Content is set up as it's own visual-studio project inside it's folder correct? See if you can muck around with just that (and not your big project that includes it).
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  21. Post #21
    Gold Member
    Hypershadsy's Avatar
    February 2008
    2,423 Posts
    How come math.random() in LOVE isn't random.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  22. Post #22
    Gold Member
    BlkDucky's Avatar
    May 2008
    6,503 Posts
    How come math.random() in LOVE isn't random.
    Because you're not seeding it, presumably.

    try putting math.randomseed(os.time()) in love.load(). Only call it once.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  23. Post #23
    Map in a box's Avatar
    July 2009
    7,420 Posts
    How come math.random() in LOVE isn't random.
    Because the seed doesn't change(but does when you call random). Just put math.random() in the update function to get better random numbers.

    Edited:

    And that
    Reply With Quote Edit / Delete Windows XP United States Show Events

  24. Post #24
    Gold Member
    Cyril's Avatar
    March 2005
    371 Posts
    Okay, I changed my code to this but it seems that the sprite is not rotating on its own center even though I made the sprite's origin in the center of the sprite:

    MouseRad = atan2(sf::Mouse::GetPosition().y - shipSpr.GetPosition().y, sf::Mouse::GetPosition().x - shipSpr.GetPosition().x);
    MouseDeg = (MouseRad) * (180/PI);
    		
    shipSpr.SetOrigin(shipSpr.GetPosition().x/2, shipSpr.GetPosition().y/2);
    shipSpr.SetRotation(MouseDeg);
    
    
    
    Instead it's rotating around a certain point on the window and it's rotation is a bit wonky:
    SetOrigin() is relative to the top left corner of the object, so instead you should use something like that :

     shipSpr.SetOrigin(shipSpr.GetTexture().GetWidth()/2, shipSpr.GetTexture().GetHeight()/2); 
    Reply With Quote Edit / Delete Linux Show Events Friendly Friendly x 1 (list)

  25. Post #25
    Exosel's Avatar
    February 2010
    1,760 Posts
    SetOrigin() is relative to the top left corner of the object, so instead you should use something like that :

     shipSpr.SetOrigin(shipSpr.GetTexture().GetWidth()/2, shipSpr.GetTexture().GetHeight()/2); 
    I tried this and it worked, it put the origin on the sprite. Now just to fix the rotation.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  26. Post #26
    Gold Member
    subenji99's Avatar
    May 2005
    3,572 Posts
    Because the seed doesn't change(but does when you call random). Just put math.random() in the update function to get better random numbers.
    That's not how a psuedo-RNG works.

    For the same seed, the order of 'random' numbers will be the same each time. Each seed value gives a different order of random numbers. This is how any procedural game with map seeds work - that seed is given to the RNG, which spits out the same 'random' numbers in the same order on any machine.

    You are just describing calling the RNG constantly - both a waste of cpu cycles and unfit for purpose - if the program runs at peak speed every time your numbers would still not be random each execution. Seeding to the current system clock guarantees that the numbers will be a different sequence each time.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  27. Post #27
    Gold Member
    Hypershadsy's Avatar
    February 2008
    2,423 Posts
    Except they still aren't even after I seed it in love.load().
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  28. Post #28
    LuaGuy's Avatar
    April 2011
    129 Posts
    well i stuck for a while, i wanna make a program with 5 column of numbers and wanna increase them whenever the user input's a number from 1 to 5 for example if the user enters 2 it will increase all of the numbers by 2. but im stuck at returning from queryFunc to main function. and without it program cant keep working. if i can do this i will add the else statement and finish my job. hope you guys can help me im a little bit beginner in C++

    #include <iostream>
    
    using namespace std;
    
    void drawFunc();
    void askFunc();
    void queryFunc();
    
    int main()
    {
        int x = 1;
    
        drawFunc();
        askFunc();
        queryFunc();
    
        return 0;
    }
    
    void drawFunc()
    {
        int x = 1;
    
        while(x <= 5)
        {
            cout << x << "|" << x << "|" << x << "|" << x << "|" << x << endl;
            x = x++;
        }
    }
    
    void askFunc()
    {
        int x = 1;
    
        cout << "Enter a number from 1 to 5: ";
        cin >> x;
    }
    
    void queryFunc()
    {
        int x = 1;
    
        if(x == 2 | 3 | 4 | 5)
        {
            /* i wanna return to the main function from here
            but i cant as i said above.
            */
        }
    }

    also defining same variable in all functions is weird i dont know how i can shorten it also is there a way to make the columns dynamic without need for go down ?
    Reply With Quote Edit / Delete Windows 7 Turkey Show Events

  29. Post #29
    Andrew McWatters
    Dennab
    March 2011
    4,658 Posts
    Except they still aren't even after I seed it in love.load().
    What OS?
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  30. Post #30
    Gold Member
    Second-gear-of-mgear's Avatar
    June 2009
    6,054 Posts
    Does anyone know how I'd make a certain date show up in a timer for Android?


    Code:
    Calendar c = Calendar.getInstance(); 
    int seconds = c.get(Calendar.SECOND)
    That is what I read to do, but I have no idea where to put this.


    Would I put it under strings.xml or layout.xml? I'm confused as hell.


    This is what I have currently:

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"   android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"   android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="30dp">
    <TextView
    android:id="@+id/day"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Day "
    android:textSize="36sp" />
    <TextView  	android:id="@+id/hour"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="00"
    android:textSize="36sp"    />
    <TextView  	android:id="@+id/min"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text=":00"
    android:textSize="36sp"    />
    <TextView  	android:id="@+id/sec"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text=":00"
    android:textSize="36sp"    />
    </LinearLayout>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="5dp"    >
    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Enter End Time :   "    />
    <EditText    	android:id="@+id/end"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"     />
    </LinearLayout>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="5dp"    >
    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Enter Start Time : "    />
    <EditText    	android:id="@+id/start"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"     />
    </LinearLayout>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="40dp"    >
    <Button    	android:id="@+id/btnstart"
    android:layout_width="wrap_content"
     android:layout_height="wrap_content"
    android:text="Start Counter"    />
    <Button    	android:id="@+id/btnstop"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Stop"    />
    </LinearLayout>
    </LinearLayout>
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  31. Post #31
    Gold Member
    ZenX2's Avatar
    February 2009
    5,129 Posts
    well i stuck for a while, i wanna make a program with 5 column of numbers and wanna increase them whenever the user input's a number from 1 to 5 for example if the user enters 2 it will increase all of the numbers by 2. but im stuck at returning from queryFunc to main function. and without it program cant keep working. if i can do this i will add the else statement and finish my job. hope you guys can help me im a little bit beginner in C++

    #include <iostream>
    
    using namespace std;
    
    void drawFunc();
    void askFunc();
    void queryFunc();
    
    int main()
    {
        int x = 1;
    
        drawFunc();
        askFunc();
        queryFunc();
    
        return 0;
    }
    
    void drawFunc()
    {
        int x = 1;
    
        while(x <= 5)
        {
            cout << x << "|" << x << "|" << x << "|" << x << "|" << x << endl;
            x = x++;
        }
    }
    
    void askFunc()
    {
        int x = 1;
    
        cout << "Enter a number from 1 to 5: ";
        cin >> x;
    }
    
    void queryFunc()
    {
        int x = 1;
    
        if(x == 2 | 3 | 4 | 5)
        {
            /* i wanna return to the main function from here
            but i cant as i said above.
            */
        }
    }

    also defining same variable in all functions is weird i dont know how i can shorten it also is there a way to make the columns dynamic without need for go down ?
    I think this will work:


    #include <iostream>
    
    using namespace std;
    
    void drawFunc(int x);
    void askFunc();
    
    int main()
    {
        int x = 1;
    
        while(true)
        {
            drawFunc(x);
            x += askFunc(); //adds to the current value of x
        }
    
        return 0;
    }
    
    void drawFunc(int x) //print five rows of five columns, each row with five columns of x plus 1 to 5.
    {
        int i = 1;
        while(i <= 5)
        {
            cout << x + i << "|" << x + i << "|" << x + i << "|" << x + i << "|" << x + i << endl;
            i++ //increment
        }
    }
    
    void askFunc()
    {
        int x = 0;
        cout << "Enter a number from 1 to 5: ";
        cin >> x;
        if((x == 1 || x == 2 || x == 3 || x == 4 || x == 5) == false) //not 1-5?
        {
            cout << "Not a valid number.";
            x = 0; //don't add anything
        }
        return x;
    }

    Edited:

    The queryFunc wasn't really necessary, and you were initializing x as 1 locally in each function.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Useful Useful x 1 (list)

  32. Post #32
    LuaGuy's Avatar
    April 2011
    129 Posts
    I think this will work:


    #include <iostream>
    
    using namespace std;
    
    void drawFunc(int x);
    void askFunc();
    
    int main()
    {
        int x = 1;
    
        while(true)
        {
            drawFunc(x);
            x += askFunc(); //adds to the current value of x
        }
    
        return 0;
    }
    
    void drawFunc(int x) //print five rows of five columns, each row with five columns of x plus 1 to 5.
    {
        int i = 1;
        while(i <= 5)
        {
            cout << x + i << "|" << x + i << "|" << x + i << "|" << x + i << "|" << x + i << endl;
            i++ //increment
        }
    }
    
    void askFunc()
    {
        int x = 0;
        cout << "Enter a number from 1 to 5: ";
        cin >> x;
        if((x == 1 || x == 2 || x == 3 || x == 4 || x == 5) == false) //not 1-5?
        {
            cout << "Not a valid number.";
            x = 0; //don't add anything
        }
        return x;
    }

    Edited:

    The queryFunc wasn't really necessary, and you were initializing x as 1 locally in each function.
    In function 'int main()':|
    error: void value not ignored as it ought to be|
    in evaluation of 'operator+=(int, void)'|
    In function 'void drawFunc(int)':|
    |28|error: expected ';' before '}' token|
    In function 'void askFunc()':|
    |41|error: return-statement with a value, in function returning 'void'|
    ||=== Build finished: 4 errors, 0 warnings ===|

    thanks for your interest but it gives bunch of errors ?
    Reply With Quote Edit / Delete Windows 7 Turkey Show Events

  33. Post #33
    Gold Member
    ZenX2's Avatar
    February 2009
    5,129 Posts
    Is this any better?

    #include <iostream>
    
    using namespace std;
    
    void drawFunc(int x);
    int askFunc(); //was void
    
    int main()
    {
        int x = 1;
    
        while(true)
        {
            drawFunc(x);
            x += askFunc(); //adds to the current value of x
        }
    
        return 0;
    }
    
    void drawFunc(int x) //print five rows of five columns, each row with five columns of x plus 1 to 5.
    {
        int i = 1;
        while(i <= 5)
        {
            cout << x + i << "|" << x + i << "|" << x + i << "|" << x + i << "|" << x + i << endl;
            i++; //increment  //forgot the semicolon
        }
    }
    
    int askFunc() //was void
    {
        int x = 0;
        cout << "Enter a number from 1 to 5: ";
        cin >> x;
        if((x == 1 || x == 2 || x == 3 || x == 4 || x == 5) == false) //not 1-5?
        {
            cout << "Not a valid number.";
            x = 0; //don't add anything
        }
        return x;
    }

    Although you should compare both to learn how to identify those types of errors
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  34. Post #34
    Gold Member
    Lord Ned's Avatar
    April 2006
    3,702 Posts
    I'm trying to use Awesonium to render to a ID3D11Texture2D (or associated ID3D11ShaderResourceView).

    I've gone through the steps of setting up Awesonium and rendering, and then I use this code:
    //Copy to buffer
    		const awe_renderbuffer *renderBuffer = awe_webview_render(webView);
    
    		if(renderBuffer)
    		{
    			//Copy buffer to texture
    			unsigned char *myBuffer;
    			myBuffer = new unsigned char[512*512*4];
    			awe_renderbuffer_copy_to(renderBuffer, myBuffer, 512 * 4, 4, true, false);
    
    			Renderer()->BindDynamicTexture2D(myBuffer);
    
    			delete[] myBuffer;
    		}
    

    (Unfortunately I have to use the C API for Awesonium due to using Visual Studio 2010).


    Where Renderer()->BindDynamicTexture2D is:
    void RenderSystem::BindDynamicTexture2D(unsigned char *buffer)
    	{
    		//Map it
    		D3D11_MAPPED_SUBRESOURCE ms;
    		GetRenderBackend()->m_pDeviceContext->Map(m_pTexture2D, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms);
    		memcpy(ms.pData, buffer, sizeof(buffer));
    		GetRenderBackend()->m_pDeviceContext->Unmap(m_pTexture2D, NULL);
    
    		//Re-bind it
    		HRESULT result = GetRenderBackend()->m_pDevice->CreateShaderResourceView(m_pTexture2D, NULL, &m_pDynamic2DView);
    	}
    

    Where m_pTexture2D is made by:
    //Create our 'dynamic' texture
    		D3D11_TEXTURE2D_DESC desc;
    		ZeroMemory(&desc, sizeof(desc));
    
    		desc.Width = 512;
    		desc.Height = 512;
    		desc.MipLevels = 1;
    		desc.ArraySize = 1;
    		desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    		desc.Usage = D3D11_USAGE_DYNAMIC;
    		desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
    		desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
    		desc.SampleDesc.Count = 1;
    
    		GetRenderBackend()->m_pDevice->CreateTexture2D(&desc, NULL, &m_pTexture2D);
    

    I then try to bind the m_pDynamic2DView to the shader and draw it on a quad. Unfortunately it just displays black. If I bind a normal texture loaded from file, it shows up fine.

    "HRESULT result = GetRenderBackend()->m_pDevice->CreateShaderResourceView(m_pTexture2D, NULL, &m_pDynamic2DView);" returns S_OK; so I think it copied the data okay, but it's obviously wrong.


    Anyone have any experience with either Awesonium or dynamic-usage ID3D11Texture2D's?
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  35. Post #35
    Clops with bisousbisous daily <3
    Mr. Smartass's Avatar
    December 2010
    9,188 Posts
    I'm working on FPS camera control, what would be the simplest way to turn the mouse difference from the center (X and Y values) into the proper rotations?
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  36. Post #36
    Philly c's Avatar
    February 2008
    563 Posts
    Where Renderer()->BindDynamicTexture2D is:
    void RenderSystem::BindDynamicTexture2D(unsigned char *buffer)
    	{
    		//Map it
    		D3D11_MAPPED_SUBRESOURCE ms;
    		GetRenderBackend()->m_pDeviceContext->Map(m_pTexture2D, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms);
    		memcpy(ms.pData, buffer, sizeof(buffer));
    		GetRenderBackend()->m_pDeviceContext->Unmap(m_pTexture2D, NULL);
    
    		//Re-bind it
    		HRESULT result = GetRenderBackend()->m_pDevice->CreateShaderResourceView(m_pTexture2D, NULL, &m_pDynamic2DView);
    	}
    
    sizeof(buffer) is the size of the pointer. Send the actual size as another parameter. Also you shouldn't need to create another view.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  37. Post #37
    Gold Member
    BlkDucky's Avatar
    May 2008
    6,503 Posts
    Except they still aren't even after I seed it in love.load().
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  38. Post #38
    LuaGuy's Avatar
    April 2011
    129 Posts
    Is this any better?

    #include <iostream>
    
    using namespace std;
    
    void drawFunc(int x);
    int askFunc(); //was void
    
    int main()
    {
        int x = 1;
    
        while(true)
        {
            drawFunc(x);
            x += askFunc(); //adds to the current value of x
        }
    
        return 0;
    }
    
    void drawFunc(int x) //print five rows of five columns, each row with five columns of x plus 1 to 5.
    {
        int i = 1;
        while(i <= 5)
        {
            cout << x + i << "|" << x + i << "|" << x + i << "|" << x + i << "|" << x + i << endl;
            i++; //increment  //forgot the semicolon
        }
    }
    
    int askFunc() //was void
    {
        int x = 0;
        cout << "Enter a number from 1 to 5: ";
        cin >> x;
        if((x == 1 || x == 2 || x == 3 || x == 4 || x == 5) == false) //not 1-5?
        {
            cout << "Not a valid number.";
            x = 0; //don't add anything
        }
        return x;
    }

    Although you should compare both to learn how to identify those types of errors
    thank you very much
    Reply With Quote Edit / Delete Windows 7 Turkey Show Events

  39. Post #39
    Gold Member
    Hypershadsy's Avatar
    February 2008
    2,423 Posts
    Windows. I'll do some testing, brb
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  40. Post #40
    Clops with bisousbisous daily <3
    Mr. Smartass's Avatar
    December 2010
    9,188 Posts
    -snop-
    Reply With Quote Edit / Delete Windows 7 United States Show Events