I am trying to get the normal rotating image on the screen. Here is my following code. I am doing this in C#, which leads to my problem of finding any help on the web for this. It seems most are using C++.
Thanks in advance.
I left out any rotation attempts I had in there since nothing was working. Thanks
public class glDraw
{
public Form1 mainWin = null;
public System.Windows.Forms.Panel panel = null;
public bool m_bAttemptedInitialization = false;
public IntPtr m_IntPtr_HWND = IntPtr.Zero;
public IntPtr m_IntPtr_HDC = IntPtr.Zero;
public IntPtr m_IntPtr_HGLRC = IntPtr.Zero;
double TxtScale = 0.05;
public int eyeDistance = 100;
double scaledTxtHeight = 0.0;
public int angle = 1;
public glDraw()
{
}
public void OneTimeInitialize(IntPtr IntPtr_HWND)
{
m_IntPtr_HWND = IntPtr_HWND;
glInitializer.Initializer.InitOpenGL("xyz", m_IntPtr_HWND, ref m_IntPtr_HDC, ref m_IntPtr_HGLRC);
scaledTxtHeight = glInitializer.Initializer.fontMetrics[(uint)'A'].gmfBlackBoxY * TxtScale;
}
public void pnlResize()
{
if (!m_bAttemptedInitialization)
{
m_bAttemptedInitialization = true;
OneTimeInitialize(panel.Handle);
}
// Set Viewport dimensions
GL.glViewport(0, 0, panel.Width, panel.Height);
glSetupRC();
panel.Invalidate(false);
}
public void pnlPaint(System.Windows.Forms.PaintEventArgs e)
{
if (!m_bAttemptedInitialization)
{
m_bAttemptedInitialization = true;
OneTimeInitialize(panel.Handle);
glSetupRC();
}
if (m_IntPtr_HGLRC != IntPtr.Zero)
{
glRenderScene();
WGL.wglSwapBuffers(m_IntPtr_HDC);
}
}
private void glSetupRC()
{
GL.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
GL.glColor3d(0.0, 1.0, 0.0);
GL.glMatrixMode(GL.GL_PROJECTION);
GL.glLoadIdentity();
GLU.gluPerspective(45, (panel.Width*1.0)/panel.Height, 10, 500);
GL.glMatrixMode(GL.GL_MODELVIEW);
GL.glFrontFace(GL.GL_CCW);
GL.glEnable(GL.GL_DEPTH_TEST);
GL.glEnable(GL.GL_COLOR_MATERIAL);
}
private void DrawTriangle()
{
GL.glBegin(GL.GL_TRIANGLES);
GL.glColor3d(.8, .6, .0);
GL.glVertex3d(-4.0, 8.0, 4.0);
GL.glVertex3d(2.0, 15.0, 0.0);
GL.glVertex3d(8.0, 8.0, 4.0);
GL.glColor3d(.6, .8, .0);
GL.glVertex3d(-4.0, 8.0, 4.0);
GL.glVertex3d(2.0, 15.0, 0.0);
GL.glVertex3d(-4.0, 8.0, -4.0);
GL.glColor3d(0.6, 0.8, .0);
GL.glVertex3d(-4.0, 8.0, -4.0);
GL.glVertex3d(2.0, 15.0, 0.0);
GL.glVertex3d(8.0, 8.0, -4.0);
GL.glColor3d(.6, .8, .0);
GL.glVertex3d(8.0, 8.0, -4.0);
GL.glVertex3d(2.0, 15.0, 0.0);
GL.glVertex3d(8.0, 8.0, 4.0);
GL.glEnd();
}
private void glRenderScene()
{
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
GL.glLoadIdentity();
GLU.gluLookAt(90, 25, eyeDistance, 0, 0, 0, 0, 1, 0);
// GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);
DrawTriangle();
}
}
And then some code on my actual form, I think this is everything I need to post
namespace Blah
{
public partial class Form1 : Form
{
glDraw plot;
public Form1()
{
InitializeComponent();
pnlGL.BackColor = Color.Transparent;
plot = new glDraw();
plot.mainWin = this;
plot.panel = pnlGL;
}
}
}