|
I will assume you are working with new OpenGL 3.3+ (If you aren't you need to switch now) you will have what amounts to a pile of Function pointers you will have got with wglGetProcAddress. Usually what you need to do is first start with that and put them in a class or object. Then build functionality on the class/object interface because you have everything contained. If you aren't comfortable with doing it yourself then use a library like GLEW which will wrangle all the function pointers for you. GLEW isn't great because you can't extend it easily but it's better than nothing.
If you haven't wrangled all the function pointers into a sort of API that is where you start.
Once you do that at a minimum you will be able to attach/change shaders and apply the matrixes to that class/object and it will store internally whatever it needs.
I usually set the class/object creation to take a window handle being the window you want to bind the OpenGL onto. The reason for doing that is when you run multiple windows each window will have it's own render context so you might as well bind the window into your object at construction. If you are using just one main OpenGL window the step will seem to have little benefit but the moment you start with multiple OpenGL windows you will get why you do it.
In vino veritas
|
|
|
|
|
How is more efficient to have, a CMap member variable created on the stack, or on the heap, even the values of CMap are just pointers:
CMap<int, int, CStringArray*, CStringArray*&> m_MapContactInfo;
or
CMap<int, int, CStringArray*, CStringArray*&>* m_pMapContactInfo;
knowing that this CMap could contain thousands of elements ...
|
|
|
|
|
Probably best on the heap if it contains large amounts of data. You also need to consider scope, i.e. how long will the object need to remain in memory?
|
|
|
|
|
"how long will the object need to remain in memory?"
As long as object that contain m_pMapContactInfo are alive ... I mean:
CMyObject::CMyObject()
{
m_pMapContactInfo = new CMap<int, int, CStringArray*, CStringArray*&>;
}
and
CMyObject::~CMyObject()
{
if(NULL != m_pMapContactInfo)
delete m_pMapContactInfo;
}
|
|
|
|
|
Flaviu2 wrote: As long as object that contain m_pMapContactInfo are alive Only you know how long that will be.
|
|
|
|
|
In fact, the m_pMapContactInfo are member variable into CView derived class ... so, as long the view are opened, the m_pMapContactInfo exist ... but what is matter how long the CMap object are exist ?
|
|
|
|
|
It only matters in that you need to place the CMap object, and all its members, in the correct place to ensure it does not get destroyed at the wrong time. The fact that you posted this question suggests that you were not sure.
|
|
|
|
|
CMap class creates its content data in the heap. It is by design.
So you can create your CMap instance on the stack and not worry!
|
|
|
|
|
"CMap class creates its content data in the heap. It is by design."
This is a good news ! (I didn't read that by now) ... thank you.
|
|
|
|
|
|
Hometurph Indi wrote: i am still not having a perfect solution with both options
Define perfect.
|
|
|
|
|
Hello Guys
I am creating a direct3D surface for further creation of OffScreenplainSurface for video sample.
And This Code was working fine before Windows10 Update.
After Update, I found that IDirect3DSurface not returning the right D3DSURFACE_DESC.format which I am using to createOffScreenPlainSurface.
Here is the Code
CComPtr<IDirect3DSurface9> sampleSurface;
MFGetService(mediaBuffer, MR_BUFFER_SERVICE, __uuidof(IDirect3DSurface9), (void**)&sampleSurface);
D3DSURFACE_DESC surfaceDesc;
sampleSurface->GetDesc(&surfaceDesc);
CComPtr<IDirect3DSurface9> sharedSampleSurface;
HANDLE shareHandleSurface = 0;
device3D->CreateOffscreenPlainSurface(
surfaceDesc.Width,
surfaceDesc.Height,
surfaceDesc.Format,
D3DPOOL_DEFAULT,
&sharedSampleSurface,
&shareHandleSurface
);
Now, after windows10 Update surfaceDesc.format = 842094158 not the D3DFMT_YUY2
And I realized that sometimes after restart of Machine, it returns D3DFMT_YUY2 which looks like some services in windows10 update obstructing MFGetService.
I found one service sppsvc which automatic delayed start and Trigger start but I am not able to get much of it.
Any Help will be Appreciated.
Thank You.
|
|
|
|
|
842094158 is 0x3231564E which is MAKEFOURCC('N', 'V', '1', '2') .
So your mediaBuffer seems to contain frames in that format.
I don't know much about Direct3D but I guess that the format has changed with the video driver installed with Windows 10.
|
|
|
|
|
Thanks Jochen for your Reply.
It makes a sense that As I read on many formuns that latest windows10 update had problem with Graphic drivers beacause it is not behaving correctly with the updates so some of them choose to roll back.
Again Thanks a Lot.
|
|
|
|
|
Hello
Is that possible that I get different Format from particular one machine and unchanged hardware?
As after Windows 10 Update, sometimes I am getting NV12 surface format and sometimes YUY2.
Thank you.
|
|
|
|
|
As I wrote, I don't know much about Direct3D. But there are some components like drivers and decoders involved which also have their own configuration.
A quick research shows that Windows is providing decompressed video streams in the YUY2 or NV12 format. So an application should probably support both formats.
|
|
|
|
|
Thanks Jochen for your reply.
I also found that Windows Supports both formats YUY2 or NV12.
But, I am struggling why it is randomly showing either format which proves that there are some setting that needs to be set As I did not get any theory/description on getting random format from these two formats.
Thanks Again for your Reply.
|
|
|
|
|
I have an ActiveX control (written originally in VC6, and later upgraded to VC 2010). When we first released it, I included a VB6 demo program to show how to use it. This all still works.
Recently, a customer requested sample code in VB 2017, and I have found that it crashes in this environment. I have also checked VB 2015 and VB 2010, and they also crash in the same place.
Here is a simplified overview of the ActiveX library:
library BoxWriter
{
interface ILine : IDispatch
{
[propget, id(8), helpstring("property m_lCount")] HRESULT m_lCount([out, retval] long *pVal);
};
interface IPrinter : IDispatch
{
[propget, id(1), helpstring("property m_line")] HRESULT m_line([optional, defaultvalue ("")] BSTR strLine, [out, retval] ILine* *pVal);
};
};
Here is a VB code snippet that causes the crash:
Dim printer As New BoxWriter.PRINTER
printer.Connect("192.168.1.3")
MsgBox(m_printer.m_line.m_lCount) ‘ <—crashes here
This is the error it gives:
An unhandled exception of type 'System.AccessViolationException' occurred in demo.exe
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
The reference returned by CPrinter::get_m_line seems to be what it is complaining about. When I debug, I see the reference is set correctly by CPrinter::get_m_line, but after the function returns, something is calling the destructor for the CLine class.
STDMETHODIMP CPrinter::get_m_line(BSTR bstrLine, ILine **pVal)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
CString strLine = (LPCTSTR)_bstr_t (bstrLine);
CComObject <CLine>* pLine = GetLine (strLine);
if (!pLine) {
return E_INVALIDARG;
}
* pVal = pLine;
return S_OK;
}
I have tried creating a new ActiveX project in VC2010, and it also exhibits the same behavior. I tried returning the reference in several different ways (property vs method), and still have not been able to solve this. Surely I am not the first person to encounter this. Can anyone suggest how to fix this?
|
|
|
|
|
At a guess your object is going out of scope and getting destroyed. You need to allocate a fixed block of memory (malloc or new) and copy the data to that block which you can then return. But that also means that the calling method will need to clean up after itself.
|
|
|
|
|
I thought that was what CComObject::AddRef was supposed to do?
|
|
|
|
|
Quite possibly but it is not clear in your code where that occurs, and if it applies to the pointer you are passing back.
|
|
|
|
|
After some experimentation (mostly due to this article: CComObject Class[^]), I have made some progress towards a fix. It seems this line, which was OK in VB6, is no longer appropriate:
CComObject <CLine> * pLine = new CComObject <CLine> ();
I replaced it with this logic, and my VB 2017 app no longer crashes:
CComObject <CLine> * pLine;
HRESULT hRes = CComObject<CLine>::CreateInstance(&pLine);
ATLASSERT(SUCCEEDED(hRes));
pLine->AddRef ();
|
|
|
|
|
This is the output I am supposed to get but I am getting errors please help me
int main()
{
int size = 5;
Shape** shapes = new Shape*[size];
Point* centre = new Point(5,5);
Rectangle* rectangle1 = new Rectangle(*centre, 4, 3);
shapes[0] = rectangle1;
shapes[1] = new Rectangle (*new Point(10, -10), 4, 4);
Rectangle* rectangle3 = new Square(*new Point(-8.5,-10), 2.5);
shapes[2] = rectangle3;
Square* square2 = new Square (*new Point(-1,-1), 1.5);
shapes[3] = square2;
Circle* circle = new Circle(*new Point(100,100), 25.4);
shapes[4] = circle;
cout << "\n11111111111111111111111111\n";
for (int i = 0; i < size; ++i)
shapes[i] -> display();
cout << "\n22222222222222222222222222\n";
cout << "\nthe area of the first rectangle is: ";
cout << rectangle1->area() << endl;
cout << "It is a square, the area is: ";
Square* square = dynamic_cast<Square*> (rectangle3);
cout << square->area() << endl;
cout << "the perimeter of the circle is: ";
cout << circle->perimeter() << endl;
cout << "\n33333333333333333333333333\n";
cout << "\nThe four vertices of the first rectangle are: (clockwise from top-left)\n";
rectangle1->printFourVertices();
cout << "\nThe four vertices of the third rectangle are:\n";
rectangle3->printFourVertices();
cout << "\n44444444444444444444444444\n";
rectangle1->reflectX();
shapes[2] -> translate(1.5, 3);
shapes[4] -> translate(-100,-100);
cout << "\nAfter reflection and translation, here are the moved shapes:\n" ;
for (int i = 0; i < size; ++i)
shapes[i] -> display();
cout << "\n55555555555555555555555555\n";
cout << "\nNow, the four vertices of the first rectangle are:\n";
rectangle1->printFourVertices();
cout << "\nNow, the four vertices of the third rectangle are:\n";
rectangle3->printFourVertices();
cout << "\n66666666666666666666666666\n\n";
for (int i = 0; i < size; ++i)
cout << shapes[i] -> area() << endl;
cout << "\n777777777777777777777777777\n";
shapes[1] -> display();
dynamic_cast<Rectangle*> (shapes[1]) -> setLength(8.2);
cout << "\nAfter setLength(8.2), the rectangle is: ";
shapes[1] -> display();
dynamic_cast<Rectangle*> (shapes[1]) -> setWidth(5);
cout << "\nAfter setWidth(5), the rectangle is: ";
shapes[1] -> display();
square2 -> display();
square2 -> setLength(8.2);
cout << "\nAfter setLength(8.2), the rectangle is: ";
square2 -> display();
square2 -> setWidth(5);
cout << "\nAfter setWidth(5), the rectangle is: ";
square2 -> display();
system("pause");
return 0;
}
This is what I have tried
#include "stdafx.h"
# include<iostream>
# include<cmath>
# include<string>
using namespace std;
class Point
{
private:
double x;
double y;
public:
Point();
Point(const double &x,const double &y);
void setX(const double &x);
void setY(const double &y);
double getX()const;
double getY()const;
double DisFromOrigin()const;
virtual void translate(const double &xDis, const double &yDis);
void reflectX(); void reflectY();
virtual void PrintName()const;
};
Point::Point()
{
x=0;
y=0;
}
Point:: Point(const double &x,const double &y)
{
this->x=x;
this->y=y;
}
void Point::setX(const double &x)
{
this->x=x;
this->y=y;
}
void Point:: setY(const double &y)
{
this->y =y;
}
double Point:: getX()const
{
return x;
}
double Point:: getY()const
{
return y;
}
double Point::DisFromOrigin()const
{
return (sqrt(x*x + y*y));
}
void Point:: translate(const double &xDis, const double &yDis)
{
double a;
double b;
a = this->x + xDis;
b= this->y + yDis;
this->x= a;
this->y=b;
}
void Point::reflectX()
{
this->y = -1 *y;
}
void Point::reflectY()
{
this->x= -1*x;
}
void Point::PrintName()const
{
cout<<"Point ("<<getX()<<" , "<<getY()<<")"<<endl;
}
class Shape
{
public:
virtual double Peri()const=0;
virtual void PrintName()const=0;
virtual void translate(double x1,double y1)=0;
virtual void reflectX()=0;
virtual void reflectY()=0;
virtual double getArea()const=0;
virtual double getPeri()=0;
virtual string getName()const=0;
}
class Circle:public Shape
{
public:
Circle();
Circle(const Point &p, const double &r);
double getR()const;
void setR(const double &r);
virtual double getPeri()const;
virtual void PrintName()const;
virtual void translate(const double &x1, const double &y1);
virtual void reflectX();
virtual void reflectY();
virtual double getArea()const;
virtual string getName()const;
protected:
Point center;
string name;
double radius;
};
Circle::Circle()
{
name = "Circle";
center = Point(0,0);
radius = 1;
}
Circle::Circle(const Point &p, const double &r)
{
name = "Circle";
this->center= p;
this->radius=r;
}
double Circle::getPeri()const
{
return (2*3.14*getR());
}
double Circle::getR()const
{
return radius;
}
void Circle::setR(const double &r)
{
this->radius = r;
}
void Circle:: PrintName()const
{
cout<<"Circle"<<endl;
}
void Circle::translate(const double &x1, const double &y1)
{
this->center.translate(x1 , y1);
}
void Circle::reflectX()
{
this->center.reflectX();
}
void Circle::reflectY()
{
this->center.reflectY();
}
double Circle::getArea()const
{
return (3.14*this->getR()*this->getR());
}
string Circle::getName()const
{
return this->name;
}
class Rectangle:public Shape
{
private:
double len;
double width;
Point center;
string name;
public:
Rectangle();
Rectangle(const Point &p, const double &len , const double &width);
void setLen(double len);
void setWid(double width);
double getLen()const;
double getWid()const;
virtual double getPeri()const;
virtual void PrintName()const;
virtual void translate(const double &x1, const double &y1);
virtual void reflectX();
virtual void reflectY();
virtual double getArea()const;
virtual string getName()const;
};
Rectangle::Rectangle()
{
len =1;
width=1;
this->name = "Rectangle";
center = Point(0,0);
}
Rectangle:: Rectangle(const Point &p, const double &len , const double &width)
{
this->name ="Rectangle";
this->center = p;
this->len = len;
this->width = width;
}
double Rectangle:: getPeri()const
{
return (2*getLen() + 2*getWid());
}
void Rectangle::PrintName()const
{
cout<<"Rectangle"<<endl;
}
void Rectangle::translate(const double &x1, const double &y1)
{
this->center.translate(x1, y1);
}
void Rectangle::reflectX()
{
this->center.reflectX();
}
void Rectangle::reflectY()
{
this->center.reflectY();
}
double Rectangle::getArea()const
{
return(getLen()*getWid());
}
string Rectangle::getName()const
{
return name;
}
void Rectangle::setLen(double len)
{
this->len = len;
}
void Rectangle::setWid(double width)
{
this->width = width;
}
double Rectangle::getLen()const
{
return len;
}
double Rectangle::getWid()const
{
return width;
}
class Square:public Rectangle
{
private:
Point center;
string name;
double side;
public:
Square();
Square(const double &side);
void setSide(const double &side);
double getSide()const;
virtual double getPeri()const;
virtual void PrintName()const;
virtual void translate(const double &x1, const double &y1);
virtual void reflectX();
virtual void reflectY();
virtual double getArea()const;
virtual string getName()const;
};
Square::Square()
{
side=0;
}
Square::Square(const double &side)
{
this->side = side;
}
void Square::setSide(const double &side)
{
this->side = side;
this->Rectangle::setLen(side);
this->Rectangle::setWid(side);
}
double Square::getSide()const
{
return this->Rectangle::getLen();
}
double Square:: getPeri()const
{
return(this->Rectangle::getLen()* 4);
}
void Square::PrintName()const
{
cout<<"Square"<<endl;
}
void Square::translate(const double &x1, const double &y1)
{
this->Rectangle::translate(x1, y1);
}
void Square::reflectX()
{
this->Rectangle::reflectX();
}
void Square::reflectY()
{
this->Rectangle::reflectY();
}
double Square::getArea()const
{
return(this->Rectangle::getLen()* this->Rectangle::getLen());
}
string Square::getName()const
{
return name;
}
int _tmain(int argc, _TCHAR* argv[])
{
int size = 5;
Shape** shapes = new Shape*[size];
Point* centre = new Point(5,5);
Rectangle* rectangle1 = new Rectangle(*centre, 4, 3); shapes[0] = rectangle1;
shapes[1] = new Rectangle (*new Point(10, -10), 4, 4);
Rectangle* rectangle3 = new Square(*new Point(-8.5,-10), 2.5);
shapes[2] = rectangle3;
Square* square2 = new Square (*new Point(-1,-1), 1.5);
shapes[3] = square2;
Circle* circle = new Circle(*new Point(100,100), 25.4);
shapes[4] = circle;
cout << "\n11111111111111111111111111\n";
for (int i = 0; i < size; ++i)
shapes[i] -> display();
return 0;
}
modified 22-Jul-17 15:46pm.
|
|
|
|
|
Do not repost questions, you have already posted the same question here, Class shape and related functions. If someone is active to answer your question, they will do it. If there is no one, reposting the question doesn't help at all.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
What kind of errors do you get ?
|
|
|
|
|