Hi guys! I have a problem: I’ve never worked with OpenGL before, but now I must understand it in short time for university task.
Task is quietly simple: Open simple AMF [en.wikipedia.org] file with OpenGL. It’s XML based file. To open and parse it there is no problem.
Ok, for test I took a simple example AMF from wiki:
Sphere20Face direct link [amf.wikispaces.com]
Which looks like sphere:
and tried to manually set vertices, here is my code:
#include "firstopengl.h"
FirstOpenGL::FirstOpenGL()
{
}
FirstOpenGL::~FirstOpenGL()
{
}
void FirstOpenGL::initializeGL(){
qglClearColor(Qt::white);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_FLAT);
//paintGL();
}
void FirstOpenGL::resizeGL(int nWidth, int nHeight){
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, (GLint)nWidth, (GLint)nHeight);
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 10.0);
}
void FirstOpenGL::paintGL(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -7.0);
glBegin(GL_TRIANGLES);
qglColor(Qt::red);
glVertex3f(-2.62866, 4.25325, 0);
glVertex3f(-0.525731, 0.850651, 0);
glVertex3f(2.62866, 4.25325, 0);
glVertex3f(-2.62866, -4.25325, 0);
glVertex3f(2.62866, -4.25325, 0);
glVertex3f(0, -2.62866, 4.25325);
glVertex3f(0, 2.62866, 4.25325);
glVertex3f(0, -2.62866, -4.25325);
glVertex3f(0, 2.62866, -4.25325);
glVertex3f(4.25325, 0, -2.62866);
glVertex3f(4.25325, 0, 2.62866);
glVertex3f(-4.25325, 0, -2.62866);
glVertex3f(-4.25325, 0, 2.62866);
glEnd();
}
Ofcourse I got trash:
Because I still don’t know what to do with normals and set’s of triangles (in AMF file in tag <triangle></triangle>).
Please help me! :)
And sorry for bad english.
↧