C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,933 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I want to make a model viewer with tao.OpenGL and I want to make an option to select and load an object I tried to upload an object but it did not work how to do it?
What I tried:
using ShadowEngine;
using ShadowEngine.ContentLoading;
OpenFileDialog ofd = new OpenFileDialog() {Filter = "obj|*.obj"};
if (ofd.ShowDialog() == DialogResult.OK)
{
FileInfo f = new FileInfo(ofd.FileName);
m = ContentManager.GetModelByName(f.Name);
m.CreateDisplayList();
}
The code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Tao.OpenGl;
using System.IO;
namespace OGSB
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
int height = simpleOpenGlControl1.Height;
int width = simpleOpenGlControl1.Width;
simpleOpenGlControl1.InitializeContexts();
Gl.glViewport(0, 0, width, height);
Gl.glMatrixMode(Gl.GL_PROJECTION);
Gl.glLoadIdentity();
Glu.gluPerspective(45.0f, (double)width / (double)height, 0.01f, 5000.0f);
}
private void simpleOpenGlControl1_Load(object sender, EventArgs e)
{
}
private void simpleOpenGlControl1_Paint(object sender, PaintEventArgs e)
{
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
Gl.glMatrixMode(Gl.GL_MODELVIEW);
Cube();
Gl.glLoadIdentity();
}
private void Cube()
{
Gl.glTranslated(0, 0, -4);
//face 1
Gl.glBegin(Gl.GL_LINE_LOOP); //start drawing GL_LINE_LOOP is the connection mode
Gl.glColor3ub(255, 0, 255);
Gl.glVertex3d(1, 1, -1);
Gl.glVertex3d(1, -1, -1);
Gl.glVertex3d(-1, -1, -1);
Gl.glVertex3d(-1, 1, -1);
Gl.glEnd();
//face 2
Gl.glBegin(Gl.GL_LINE_LOOP);
Gl.glColor3ub(0, 255, 255);
Gl.glVertex3d(-1, -1, -1);
Gl.glVertex3d(1, -1, -1);
Gl.glVertex3d(1, -1, 1);
Gl.glVertex3d(-1, -1, 1);
Gl.glEnd();
//face 3
Gl.glBegin(Gl.GL_LINE_LOOP);
Gl.glColor3ub(255, 255, 0);
Gl.glVertex3d(-1, 1, -1);
Gl.glVertex3d(-1, -1, -1);
Gl.glVertex3d(-1, -1, 1);
Gl.glVertex3d(-1, 1, 1);
Gl.glEnd();
//face 4
Gl.glBegin(Gl.GL_LINE_LOOP);
Gl.glColor3ub(0, 0, 255);
Gl.glVertex3d(1, 1, 1);
Gl.glVertex3d(1, -1, 1);
Gl.glVertex3d(1, -1, -1);
Gl.glVertex3d(1, 1, -1);
Gl.glEnd();
//face 5
Gl.glBegin(Gl.GL_LINE_LOOP);
Gl.glColor3ub(0, 255, 0);
Gl.glVertex3d(-1, 1, -1);
Gl.glVertex3d(-1, 1, 1);
Gl.glVertex3d(1, 1, 1);
Gl.glVertex3d(1, 1, -1);
Gl.glEnd();
//face 6
Gl.glBegin(Gl.GL_LINE_LOOP);
Gl.glColor4d(255, 0, 0, 100);
Gl.glVertex3d(-1, 1, 1);
Gl.glVertex3d(-1, -1, 1);
Gl.glVertex3d(1, -1, 1);
Gl.glVertex3d(1, 1, 1);
Gl.glEnd();
}
private void objToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void simpleOpenGlControl1_MouseClick(object sender, MouseEventArgs e)
{
}
}
}