This project is read-only.

Getting OpenGL object from a different event handler

Mar 8, 2012 at 12:40 AM

Hi. I had a question about how to access the OpenGL object from a method other than 

private void openGLControl_OpenGLDraw(object sender, SharpGL.OpenGLEventArgs args).

 

Basically, I want to get the OpenGL object inside the method

 

private void openGLControl_MouseMove(object sender, MouseEventArgs e){

}

but I can't use the args.OpenGL that I normally do. How else can I access this object?

 

Mar 9, 2012 at 8:47 AM

Hi,

just use openGLControl.OpenGL.

Each OpenGL control exposes its OpenGL instance through this property

Mar 9, 2012 at 3:25 PM
dwmkerr wrote:

Hi,

just use openGLControl.OpenGL.

Each OpenGL control exposes its OpenGL instance through this property

Thank you for your response. It appears the version of the DLL I have is from before that property was added. I've updated my DLLs and it's worked as I expected. 

Mar 21, 2012 at 7:28 PM

Hi

I think i have the same problem. I want use gl.begin in method of class, but when i try use openGLControl.OpenGL, compilator send a message "The name 'openGLControl' does not exist in the current context" in C++ this look like this

void CKolo::rysuj()
{
	if(this->hide==0)
	{
		glPushMatrix();
			glTranslatef(this->srodek.y,this->srodek.x,this->srodek.z);
			glRotatef(this->kat,0,0,1);
			glColor3f(this->kolor[0],this->kolor[1],this->kolor[2]);
			glBegin(GL_POLYGON);
				for(float kat=0;kat<360;kat+=10)
				{
					float x,y;
					x=r*cos(kat/180*3.14);
					y=r*sin(kat/180*3.14);
					glVertex2f(x,y);
				}
			glEnd();
		glPopMatrix();
	}
}

and in dislplay func like that

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_LIGHTING);
    glColor3d(1,0,0);
		glPushMatrix();
			glTranslated(0, 0, -100);

			czolg.rysuj();//here

		glPopMatrix();
    glutSwapBuffers();
 

Mar 26, 2012 at 11:41 AM

Hi CrazyBaran,

Go to the form you're doing the work in, click on the OpenGL control, check it's name in the properties window. It'll probably be 'openGLCtrl1' - then use the name to get OGL, such as:

openGlCtrl1.OpenGl.Etc