
I made my mind. MFC is too much of a hassle. It crossed my mind to make a new thread, but I thought it would be better to keep rolling with this one.







#include <iostream>
#include <conio.h>
using namespace std;
float addition (float &a, float &b){
float sum = a + b;
b+=b;
return sum;}
float int{
float x, y, c, d;{
cout<<"Masukan nilai x : ";
cin>>x;
cout<<"Masukan nilai y : ";
cin>>y;
c = 6;
d = 4;
cout << "Nilai x sebelum memanggil fungsi addition = " << c << endl;
cout << "Nilai y sebelum memanggil fungsi addition = " << d << endl;
cout << " " <<endl;
cout<<addition(c,d);
="" cout<<="" "nilai="" setelah="" memanggil="" fungsi="" addition"="" <<endl;
="" cout<<"nilai="" penjumlahannya="" adalah="" :"="" <<endl;
getch();}<pre="">





Try to move all the '{' and '}' symbols to the new lines and properly format the resulting code...





float int{
Well, that's not going to work, now is it?
Also, you have more opening braces "{ " than closing braces "} ".
Keep Calm and Carry On





Where's main() ?
"One man's wage rise is another man's price increase."  Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it."  Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him."  James D. Miles





Hi all,
I am a hobbyist developer and I am recycling myself with the intention of learning C++ and D3D11. To give you an idea, I have been using for more than a decade a D3D9 engine with a programming language very similar to C. After doing several D3D11 tutorials, I think I understand fairly well where the shots are going.
The thing is that these tutorials lack an architecture designed to be scaled and they all end up in a function that does everything at once. Reading around, I have found a small explanation of how to combine in a simple way all the buffers that have to be associated to the pipeline to end up drawing on the screen, but I can't make it work.
The system is based on a class called 'Bindable' that contains a virtual function to associate the buffers to the pipeline and that is configured to be 'friendly' to the class that initializes the graphics (Graphics) to be able to access its private members.
class Bindable {
public:
virtual void Bind(Graphics& _gfx) noexcept = 0;
virtual ~Bindable() = default;
protected:
static ID3D11DeviceContext* GetContext(Graphics& _gfx) noexcept;
static ID3D11Device* GetDevice(Graphics& _gfx) noexcept;
};
I expand this class for each type of buffer with its specific constructor and dinder. For example, the mesh index buffer, which contains a pointer to the buffer and the number of indexes, looks like this:
class IndexBuffer : public Bindable {
public:
IndexBuffer(Graphics& _gfx, const std::vector<unsigned short>& _indices);
void Bind(Graphics& _gfx) noexcept override;
UINT GetCount() const noexcept;
private:
UINT m_count;
Microsoft::WRL::ComPtr<ID3D11Buffer> mp_buffer;
};
The implementation is very simple:
IndexBuffer::IndexBuffer(Graphics& _gfx, const std::vector<unsigned short>& _indices)
:
m_count((UINT)_indices.size())
{
D3D11_BUFFER_DESC _ibd = {};
_ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
_ibd.Usage = D3D11_USAGE_DEFAULT;
_ibd.CPUAccessFlags = 0u;
_ibd.MiscFlags = 0u;
_ibd.ByteWidth = UINT(m_count * sizeof(unsigned short));
_ibd.StructureByteStride = sizeof(unsigned short);
D3D11_SUBRESOURCE_DATA _isd = {};
_isd.pSysMem = _indices.data();
GetDevice(_gfx)>CreateBuffer(
&_ibd,
&_isd,
&mp_buffer
)
}
void IndexBuffer::Bind(Graphics& _gfx) noexcept {
GetContext(_gfx)>IASetIndexBuffer(
mp_buffer.Get(),
DXGI_FORMAT_R16_UINT,
0u
);
}
UINT IndexBuffer::GetCount() const noexcept {
return m_count;
}
In the class that manages the initialization of D3D11, a function includes the instances of the DirectX buffer classes in a vector and returns their index in the list.
std::vector<std::unique_ptr<Bindable>> m_binds;
...
UINT Graphics::AddBind(std::unique_ptr<Bindable> _bind) noexcept(!IS_DEBUG) {
m_binds.push_back(std::move(_bind));
return m_binds.size()  1;
}
As a test method, I create instances of the 'Bindable' heir classes and save their index in order to associate their buffers in subsequent frames. All in the same function, by the moment.
if (m_ibufIndex < 0)
m_ibufIndex = AddBind(std::make_unique<IndexBuffer>(*this, _indices));
else
m_binds[m_ibufIndex].get()>Bind(*this);
This way, I intend to be able to associate all the buffers for each actor in the scene by means of a list of indexes and thus also be able to reuse the same buffers in different actors, although I haven't written this part yet, as I have found that the buffers are not associated to the pipeline correctly. When I call 'ID3D11DeviceContext::DrawIndexed' I get a warning that says the following:
Quote: ID3D11DeviceContext::DrawIndexed: An Index Buffer is expected, but none is bound. This is OK, as reading from a missing Index Buffer is defined to return 0. However the developer probably did not intend to make use of this behavior.
The thing is that the code compiles without problems and I have been able to verify, with the invaluable help of ImGui, that the instances of 'Bindable' are certainly created and that the buffers exist. For this purpose, I have added a member to the 'IndexBuffer' class that returns the description of the buffer and that I check right after the 'Bindable' creation/association block and it certainly exists.
I have tried to reinterpret the pointers hosted in 'm_binds' to their corresponding class, although I am pretty sure that it is not necessary.
((IndexBuffer*)(m_binds[m_ibufIndex].get()))>Bind(*this);
Does anyone have any idea what might keep buffers from being associated with the pipeline?
If someone could shed some light on the matter I'd be very grateful.
Greetings and thank you for your time,
txes
modified 4Apr20 11:00am.





You should really check the return values when creating buffers  you might find the graphics card doesn't want to create a 16bit buffer or something annoying like that. Direct3D11 will happily run though a load of code that does nothing because something at the start wasn't set up properly.
I would step through in the debugger and check that everything is being assigned, and especially that the index buffer is being set to a real value and not nullptr.





Thank you for your answer, Graham.
I actually do check all the returns, I just squeezed down the code to the minimum. Even I check the data from gdiplus.h, that's where the warning come from. Every D3D11 function call is wrapped into an exception thrower.
I already have a straight function where the buffers are created and released every frame that works. I am trying to replace all those creations, step by step, by preloaded buffers, but with no luck.
To be clearer, I am trying to sustitute index and vertex buffers creations by the corresponding classes from a function that already draws a rotating cube. The mesh description is the very same.
```
// Vertex buffer description
wrl::ComPtr<ID3D11Buffer> _vertexBuf;
D3D11_BUFFER_DESC _vbd = {};
_vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
_vbd.Usage = D3D11_USAGE_DEFAULT;
_vbd.CPUAccessFlags = 0u;
_vbd.MiscFlags = 0u;
_vbd.ByteWidth = sizeof(_vertices);
_vbd.StructureByteStride = sizeof(Vertex);
D3D11_SUBRESOURCE_DATA _vsd = {};
_vsd.pSysMem = _vertices;
// Create vertex buffer
GFX_THROW_INFO(_hr,
mp_device>CreateBuffer(&_vbd, &_vsd, &_vertexBuf)
);
// Bind vertex buffer to pipeline
const UINT _stride = sizeof(Vertex);
const UINT _offset = 0u;
GFX_THROW_INFO_ONLY(_v,
mp_context>IASetVertexBuffers(
0u,
1u,
_vertexBuf.GetAddressOf(),
&_stride,
&_offset
)
);
// Index buffer description
wrl::ComPtr<ID3D11Buffer> _indexBuf;
D3D11_BUFFER_DESC _ibd = {};
_ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
_ibd.Usage = D3D11_USAGE_DEFAULT;
_ibd.CPUAccessFlags = 0u;
_ibd.MiscFlags = 0u;
_ibd.ByteWidth = sizeof(_indices);
_ibd.StructureByteStride = sizeof(unsigned short);
D3D11_SUBRESOURCE_DATA _isd = {};
_isd.pSysMem = _indices;
// Create index buffer
GFX_THROW_INFO(_hr,
mp_device>CreateBuffer(&_ibd, &_isd, &_indexBuf)
);
// Bind index buffer to pipeline
GFX_THROW_INFO_ONLY(_v,
mp_context>IASetIndexBuffer(
_indexBuf.Get(),
DXGI_FORMAT_R16_UINT,
0u
)
);
I intend to replace the top with the bottom
if (m_indexCount == 0) {
// temporary, just a build of vectors from local arrays
std::vector<Vertex> _verts;
for (int _i = 0; _i < 8; _i += 1)
_verts.push_back(_vertices[_i]);
std::vector<unsigned short> _inds;
for (int _i = 0; _i < 36; _i += 1)
_inds.push_back(_indices[_i]);
m_indexCount = _inds.size();
m_ibufIndex = AddBind(std::make_unique<IndexBuffer>(*this, _inds));
m_vbufIndex = AddBind(std::make_unique<VertexBuffer>(*this, _verts));
} else {
((IndexBuffer*)(m_binds[m_ibufIndex].get()))>Bind(*this);
((VertexBuffer*)(m_binds[m_vbufIndex].get()))>Bind(*this);
}






Oh my god. I only forgot to bind the buffers just before creation, in the very first frame. What a silly error. I apologize for your lost time.
Thank you very much for your support. It is really appreciated.
Greets,
txes





I wanna implement an algorithm for Facial Recognition in C++ with the help of ViolaJones, aka Adaboost, but without using OpenCV or any other similar library. I wanna do it all from scratch. Any tips?
Everybody gives me ambiguous answers.
P.S.: I started the whole thing by creating a RGB to grayscale Bitmap conversion.






A way to accomplish this is use the source code from a library that do that, which is huge work ... even is a school work, I guess it can be used OpenCV directly, most of them are free.





I have a tough time finding the inverse sinus math function in c++. There is asinf() but I`m not sure about what it does. [fixed] Displaying a float in StringCchPrintfA
modified 3Apr20 4:00am.







The documentation of asin should be just enoough: '(it) Computes the principal value of the arc sine of arg'
That is you get the first quadrant angle correnspondig to the sin value passed as argument.
The following program
#include <cmath>
#include <iostream>
using namespace std;
int main()
{
const size_t N = 18;
const double delta = M_PI/N;
for ( double phi = 0; phi < 2*M_PI; phi += delta)
{
double s = sin(phi);
double a = asin(s);
cout << "phi = " << phi << ", sin(phi) = " << s << ", asin(sin(phi)) = " << a << "\n";
}
cout << endl;
}
outputs
phi = 0, sin(phi) = 0, asin(sin(phi)) = 0
phi = 0.174533, sin(phi) = 0.173648, asin(sin(phi)) = 0.174533
phi = 0.349066, sin(phi) = 0.34202, asin(sin(phi)) = 0.349066
phi = 0.523599, sin(phi) = 0.5, asin(sin(phi)) = 0.523599
phi = 0.698132, sin(phi) = 0.642788, asin(sin(phi)) = 0.698132
phi = 0.872665, sin(phi) = 0.766044, asin(sin(phi)) = 0.872665
phi = 1.0472, sin(phi) = 0.866025, asin(sin(phi)) = 1.0472
phi = 1.22173, sin(phi) = 0.939693, asin(sin(phi)) = 1.22173
phi = 1.39626, sin(phi) = 0.984808, asin(sin(phi)) = 1.39626
phi = 1.5708, sin(phi) = 1, asin(sin(phi)) = 1.5708
phi = 1.74533, sin(phi) = 0.984808, asin(sin(phi)) = 1.39626
phi = 1.91986, sin(phi) = 0.939693, asin(sin(phi)) = 1.22173
phi = 2.0944, sin(phi) = 0.866025, asin(sin(phi)) = 1.0472
phi = 2.26893, sin(phi) = 0.766044, asin(sin(phi)) = 0.872665
phi = 2.44346, sin(phi) = 0.642788, asin(sin(phi)) = 0.698132
phi = 2.61799, sin(phi) = 0.5, asin(sin(phi)) = 0.523599
phi = 2.79253, sin(phi) = 0.34202, asin(sin(phi)) = 0.349066
phi = 2.96706, sin(phi) = 0.173648, asin(sin(phi)) = 0.174533
phi = 3.14159, sin(phi) = 1.45473e15, asin(sin(phi)) = 1.45473e15
phi = 3.31613, sin(phi) = 0.173648, asin(sin(phi)) = 0.174533
phi = 3.49066, sin(phi) = 0.34202, asin(sin(phi)) = 0.349066
phi = 3.66519, sin(phi) = 0.5, asin(sin(phi)) = 0.523599
phi = 3.83972, sin(phi) = 0.642788, asin(sin(phi)) = 0.698132
phi = 4.01426, sin(phi) = 0.766044, asin(sin(phi)) = 0.872665
phi = 4.18879, sin(phi) = 0.866025, asin(sin(phi)) = 1.0472
phi = 4.36332, sin(phi) = 0.939693, asin(sin(phi)) = 1.22173
phi = 4.53786, sin(phi) = 0.984808, asin(sin(phi)) = 1.39626
phi = 4.71239, sin(phi) = 1, asin(sin(phi)) = 1.5708
phi = 4.88692, sin(phi) = 0.984808, asin(sin(phi)) = 1.39626
phi = 5.06145, sin(phi) = 0.939693, asin(sin(phi)) = 1.22173
phi = 5.23599, sin(phi) = 0.866025, asin(sin(phi)) = 1.0472
phi = 5.41052, sin(phi) = 0.766044, asin(sin(phi)) = 0.872665
phi = 5.58505, sin(phi) = 0.642788, asin(sin(phi)) = 0.698132
phi = 5.75959, sin(phi) = 0.5, asin(sin(phi)) = 0.523599
phi = 5.93412, sin(phi) = 0.34202, asin(sin(phi)) = 0.349066
phi = 6.10865, sin(phi) = 0.173648, asin(sin(phi)) = 0.174533
phi = 6.28319, sin(phi) = 4.68582e15, asin(sin(phi)) = 4.68582e15





I`m doing something wrong. In a right triangle the hypotenuse length is 80.62 the triangle side length opposing the angle is 40. The windows calculator result for inverse sin 40/80.6225 is 29.74 When I do the math with asinf() I`m getting 0.519





Post your code, then.
The following program
#include <cmath>
#include <iostream>
using namespace std;
int main()
{
double angle = asin( 40/80.6225 );
cout << "angle " << angle << " (" << (angle * 180 / M_PI) << " degrees)" << endl;
} Outputs
angle 0.519147 (29.7449 degrees)





after conversion the result is as it should be , thanks






You probably mix degrees with radians.





