Jump to content

  • Log In with Google      Sign In   
  • Create Account

noodleBowl

Member Since 08 Sep 2013
Offline Last Active Today, 02:13 AM

#5266794 Using GLES2/3 depending on hardware (Android)

Posted by noodleBowl on 17 December 2015 - 12:52 PM

#ifdef USING_GLES3
const EGLint attribs2[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
#else
const EGLint attribs2[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
#endif
context = eglCreateContext(display, config, NULL, attribs2);


This would not work, because you are doing the USING_GLES3 if statement. What you have here would be a compile time thing.
You want a run time thing. I was thinking something like this


EGLint attribsES3[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
context = eglCreateContext(display, config, NULL, attribsES3);
if(context == EGL_NO_CONTEXT)
{
   //We failed to create the ES 3 context. Try ES 2
   EGLint attribsES2[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
   context = eglCreateContext(display, config, NULL, attribsES2);
   if(context == EGL_NO_CONTEXT)
   {
       //Something is wrong... Failed to create the ES2 context
       LogError("Failed to create a supported ES Context");
   }
}

//Other code to create the EGL Display




#5263326 IDE for Android NDK

Posted by noodleBowl on 23 November 2015 - 03:20 PM

I started using vs 2015. It supports ndk debugging, and the emulator is smooth and fast.


VS 2015 works great for me, although I pretty much just using it for intellisense when it comes to android. The emulator can't run opengl calls for me and the NDK debugging part won't work cause my device is too old. Otherwise awesome smile.png


#5262863 MyClass myClass VS myClass = new MyClass()

Posted by noodleBowl on 20 November 2015 - 08:39 AM

I was wondering if someone could tell me the difference between:

MyClass class;

And
 

MyClass *myClass;
myClass = new MyClass();

Other than the second block of code is making a dynamic memory allocation and that I must delete it when I'm done with it otherwise I'll suffer memory leaks.

 

But what I mean is which one should I be using the most? Does it matter even?

Would it be bad to have all of my custom classes created using the dynamic memory way?

 




#5262074 Member function pointers?

Posted by noodleBowl on 14 November 2015 - 09:08 PM

From your previous code, simply do :

anotherStruct->callback->MyFunctionPointer = MyFunction;

Unfortunately when using the struct code, I get a syntax error unless MyFunction is static. I get:
a value of type "void (TestClass::*)()" cannot be assigned to an entity of type "void (*)()"

If I am to do:
anotherStruct->callback->MyFunctionPointer = &this->MyFunction;

I get the error:
ISO C++ forbids taking the address of a bound member function to form a pointer to member function. Say '&TestClass::MyFunction' [-fpermissive]


#5262051 Member function pointers?

Posted by noodleBowl on 14 November 2015 - 04:29 PM

It's all about how functions are stored.

Thanks for the awesome example! I definitely appreciate it

I see that the function pointer of AnotherClass is: void (TestClass::*fMyFunctionPtr)()
Would it be possible to set the function pointer if it was just: void (*fMyFunctionPtr)()
or does it need to include the AnotherClass type?

How would it be possible to do the same if AnotherClass was really AnotherStruct?
Looking something like this, where AnotherStruct is kept 'pure' (no adding of outside classes or etc)?
//In AnotherStruct.hpp
typedef struct AnotherStruct
{

  struct AnotherStructCallback *callback;

} AnotherStruct;

typedef struct AnotherStructCallback
{

  void (*MyFunctionPointer)();

} AnotherStruckCallback

//============================

//In TestClass header file
void Init(AnotherStruct *anotherStruct);
void MyFunction();

//In TestClass imp file
void Init(AnotherStruct *anotherStruct)
{
    //Assign the MyFunctionPointer to the member method MyFunction
    anotherStruct->callback->MyFunctionPointer = ?????;

}



#5261999 Member function pointers?

Posted by noodleBowl on 14 November 2015 - 05:46 AM

make the member function "static", then you can just assign it to the function pointer normally


If the function is not static am I still allowed to assign it?
I see that I get a "a pointer to a bound function may only be called" syntax error when trying
I'm not really sure if I'm on the right track with the first section you talked about
 
//In header file
void (TestClass::*MyFunctionPtr)(AnotherObject *anotherObject);
void MyFunction(AnotherObject *anotherObject);

//In imp file
MyFunctionPtr = &TestClass::MyFunction;
anotherObject->callback = this->*MyFunctionPtr;

If you use C++11 onward, you  should use std::function and combine it with std::bind.


I went ahead and gave this ago, but I get tripped up at the std::bind
My issue there is that I am trying to use a 'this' in the second param since I want to keep it inside the TestClass::Init function

Besides the fact that I get an error
Is doing something like this not going to happen? Because of the 'this':
//In the header file
std::function<void(AnotehrObject *anotherObject)> MyFunctionFunc;
void TestClass::MyFunction();


//In the imp file (inside the init function of TestClass)
MyFunctionFunc = std::bind(TestClass::MyFunction, this); //causes error on type conversion




#5260538 Quickest way to glBufferSubData

Posted by noodleBowl on 04 November 2015 - 12:26 PM

I was wondering what is the best way to put data to a buffer using glBufferSubData?
I'm talking in the sense that since I can't map directly into the buffer what should I do?

Do I make a Vector and then just use the call?
std::vector<GLfloat> vec;

//Code that puts  data into the vector

glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(GLfloat) * DataSize, &vec[0]);



#5257362 What are my options for loading my game files for an android app?

Posted by noodleBowl on 15 October 2015 - 11:12 AM

In my opinion you should use the AssetManager

Then you just need to create a folder named assets and drop your folder structure in there.
Then using the AssetManager you can load your files like this:
 

//Java code
AssetManager assetManager = myActivity.getAssets();

//Load the file from the shaders folder.
// Folder struct:
// - OtherFolders
// - res
// - assets
//     - Shaders
//        -myShader.txt
//The assets part is automatically added in the function below. So you don't need to work about it
InputStream fileInputStream = assetManager.open("Shader/myShader.txt"); 




#5247931 Scrolling background logic?

Posted by noodleBowl on 20 August 2015 - 02:29 PM

Right now I am thinking of it like a typewriter. When the head gets to the end, it jumps back to the first position and repeats that. Am I clos?

 

You are definitely on the right track. Basically, you draw your background twice.

 

So you have two instances of your background: A and B. As background A moves along you draw background B trailing behind it right behind it. Then when background A completely passes your screen threshold you can "jump" background A back to its starting position and background B should then follow. Jumping right behind, creating a endless scrolling effect.

Microsoft has an example article using their XNA framework, which should be super easy to get going in whatever framework you are working in
https://msdn.microsoft.com/en-us/library/Bb203868.aspx




#5247657 Different Resolutions

Posted by noodleBowl on 19 August 2015 - 08:36 AM

I have thought about this for a bit and trying to figure out what to do. As of now what I got:
 
So I have a min and max aspect ratio. Where my min aspect ratio is 3:2 and my max aspect ratio is 5:3
I draw all of my sprites, background, HUD elements, etc geared towards the 5:3 ratio. The resolution of this ratio also engulfs all of my other aspect ratios.
 
When it comes to the devices and graphics, I determine the scale factor by doing
xScale = deviceResWidth / TARGET_RES_WIDTH_53;
yScale = deviceResHeight / TARGET_RES_HEIGHT_53;
and scale it up or down based on this value.
Then when it comes to the logic and playing field these things are all geared towards the 3:2 resolution. Allowing everyone to be on the same playing field, no pun intended.
 
 
My other thought was to maybe just draw all the sprites geared towards the 3:2 resolution. Then have the backgrounds (maybe HUD too) drawn to the 5:3 resolution.
Then each one gets scaled accordingly

xScale = deviceResWidth / TARGET_RES_WIDTH_32;
yScale = deviceResHeight / TARGET_RES_HEIGHT_32;

xScaleBackgrounds = deviceResWidth / TARGET_RES_WIDTH_53;
yScaleBackgrounds = deviceResHeight / TARGET_RES_HEIGHT_53;




#5245145 Velocity and deltatime confusion

Posted by noodleBowl on 08 August 2015 - 02:33 PM

deltaTime should be used when the change in velocity is a force. If it's a one-time instantaneous change, then you can do it like you've written there.

So the question is: The next frame, if the player is still in the water, are you going to halve their velocity again? (If so, use a force) Or do you only halve their velocity when they first enter the water? (If so, do what you're doing now)

 

In this case it would be a one time deal. If the player hits the object, half their current velocity.

 

 

You're moving at 600 units per what? Per second? Per minute? Per hour?

Normally we assume it's per second.
If we're simulating at 16.67ms per frame, then the object is moving at 10 units per frame.

Likewise, if the deacceleration is instantaneous, then you just divide the velocity by 2. Because it happens in that frame. Think in frames. Because you're dividing time (which is contiguous) into discrete frames.

 

Now if instead, hitting the poodle deaccelerates the object over a second, then you need subtract half of the velocity during 60 frames over and over again and multiply it by delta time (16.67ms). Because 60 times 0.016666667 is 1.

 

Think in time and frames.

 

I was thinking in terms of I'm just moving at a rate of 600 units or that is my current velocity.

 

But either way in the case I was talking about it would be all in the one frame so it would just be:

velocity -= velocity * 0.5f;

Now in the case where I hit the poodle ;)

And the poodle makes me slow down my velocity over the time I'm colliding with them by half (or over a 60 frames assuming we are stimulating 16.67ms )

Then if I am correct my equation should be:

 
if(player.collides(poodle))
    player.velocity -= player.velocity * 0.5f * deltatime;
 



#5244479 High Speed Collision Detection

Posted by noodleBowl on 04 August 2015 - 06:58 AM

What you described there has actually a name smile.png

It's Continuous Collision Detection (see here for example: https://en.wikipedia.org/wiki/Collision_detection#A_posteriori_.28discrete.29_versus_a_priori_.28continuous.29 )

 

Most Physics engines have switches to enable CCD for certain bodies (e.g. bullets, rockets, stuff like that) but often have it disabled by default since it is more costly than the standard simulation.

 

Edit: This page has some nice graphics explaining the stuff as well: http://www.stencyl.com/help/view/continuous-collision-detection/

 

Awesome! Thanks for the links

 

Is it really that costly? I means its just a line test right?




#5244338 High Speed Collision Detection

Posted by noodleBowl on 03 August 2015 - 12:00 PM

I have objects that gain velocity over time and eventually they move pretty fast. Which makes me worried about my collision detection holding up. I mean eventually I know they are going to be moving so fast they tunnel. So I was wondering if this method would work?

 

My idea is to cast a ray out in the direction that the object is moving. This ray would start from the object's edge at the center and its length would be the current velocity of the object. During the collision detection phase I would do a line intersection test with the hitbox of my other collidable objects. If the test passes I can assume that a collision will occur and handle it next frame

 

Has anyone tried something like this? Or what have you guys done?

 




#5243617 2D Platformer Camera

Posted by noodleBowl on 30 July 2015 - 12:16 PM

I know how to scroll the camera by altering its (X,Y) coordinates within the overworld width and height, but how do I figure out which tiles to draw on the canvas (only the tiles within the camera's view, including partial tiles)?


TBH, I don't think its worth it to try to "cull" the tiles

I'm not sure what framework / lib you are using, but I am assuming since this is a 2D game you are using a sprite batcher to draw stuff. Internally, I would think that the sprite batcher would cull off things that are not on the screen. Basically speaking in terms of the GPU, sprites added to a batch that are actually off screen wont make it past the fragment shader stage. Saving you some GPU time.

However, they are not being culled off on the CPU side of things. In order to cull them off on the CPU side of things, this would require some kind of check. Such as:

for(int i = 0; i < tiles.length; ++i)
{
   if(tile[i].Intersects(ScreenBox)
      tile[i].Draw(spriteBatch);
}

BUT the reason I say its not worth it is because this check still costs CPU time. So in the end you are probably going to end up spending more CPU time just doing the check, then just telling the sprite batcher to draw it and have the GPU deal with culling it. 




#5240103 Why is my constructor/Renderer class being called twice?

Posted by noodleBowl on 13 July 2015 - 11:59 AM

View constructors can be called *a lot* on Android. For example, configurations changes (such as rotating your device from portrait to landscape) cause the entire view stack to be torn down and recreated. I'd trace through the View constructor that is calling setRenderer(), and make absolutely sure it is only being called once.

What swiftcoder says is very very true here

 

When your screen changes orientation or your activity gets paused, your OpenGL context is destroyed and recreated.

Actually when the screen orientation changes IIRC the whole activity gets destroyed and recreated

 

Personally I would follow haegarrs advice and set a break point. Place it on the first line of the onCreate method that you override, that way you can step through from the beginning of your apps creation.






PARTNERS