Шустрый

Профиль
Группа: Участник
Сообщений: 88
Регистрация: 8.5.2012
Репутация: нет Всего: 1
|
Вот этот код компилируется и рисует кривую. Но мне надо нарисовать по тех точках что закоментированы и их 6 а не 4. Ничего не видно после компиляции и запуска. В чем дело? Окно просто не захватывает (rezize, Viewport) эту кривую или надо что то менять в параметрах? Здесь непонятен один момент--здесь сегментов 20, а как они определяются? Как и glEvalCoord1d()--если дело в ней здесь? | Код | #include <iostream> #include <stdlib.h> #include "windows.h" #include <GL/glut.h> // GLUT stuff - includes OpenGL headers
// For Bezier curve const int numcontrolpts = 4; // Number of control points --nado mne 6 // Below are coord's of control points // (Must use 3 coord's each, even in 2-D.) GLfloat controlpts[numcontrolpts][3] = { {-0.9, -0.9, 0.0}, {-0.5, 0.2, 0.0}, { 0.9, -0.9, 0.0}, { 0.9, 0.9, 0.0} };
//const int numcontrolpts = 6; //{ // {3, 11, 0.0}, //{7, 16, 0.0}, // { 4, 7, 0.0}, // { 13, 14, 0.0}, // { 6, 3, 0.0}, // { 11, 1, 0.0} //};
int numdrawsegs = 20; // Number of segments drawn in the Bezier curve
const int startwinsize = 400; // Starting window width & height, in pixels
// The GLUT display function void display() { // Clear screen glClear(GL_COLOR_BUFFER_BIT);
// Draw Bezier curve glColor3d(0.9, 0.1, 0.1); glLineWidth(3.0);
glEvalMesh1(GL_LINE, 0, numdrawsegs);
// Here, We used an evaluator grid. // Code to do the same thing, "manually", is as follows:
//glBegin(GL_LINE_STRIP); // for (int i=0; i<=numdrawsegs; ++i) // glEvalCoord1d(GLdouble(i)/numdrawsegs); //glEnd();
glutSwapBuffers(); }
// The GLUT reshape function void reshape(int w, int h) { glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION); glLoadIdentity(); // We set up coordinate system so that aspect ratios are always correct, // and the region from -1..1 in x & y always just fits in the viewport. if (w > h) { gluOrtho2D(-double(w)/h, double(w)/h, -1., 1.); } else { gluOrtho2D( -1., 1., -double(h)/w, double(h)/w); }
glMatrixMode(GL_MODELVIEW); // Always go back to modelview mode glLoadIdentity(); }
// The GLUT keyboard function void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: // Escape Key -- good way to quit exit(0); // Quit break; } }
// Initializes GL states void init() { // Set background color glClearColor(1.0, 1.0, 1.0, 0.0);
// Set up Bezier curve evaluator glMap1f(GL_MAP1_VERTEX_3, // target: 1-d [curve], 3 coord's per pt 0.0, 1.0, // start & end param value 3, // "stride": pts stored 3 GLfloat's apart numcontrolpts, // no. of control points &controlpts[0][0]); // control pt data glEnable(GL_MAP1_VERTEX_3); // Enable this evaluator
// Set up grid for evaluator. // This only needs to be done when using glEvalMesh1. glMapGrid1d(numdrawsegs, 0.0, 1.0); }
int main(int argc, char ** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(startwinsize, startwinsize); glutInitWindowPosition(50, 50); glutCreateWindow("CS 381 - Simple OpenGL Evaluator Demo");
init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard);
glutMainLoop();
return 0; } |
Модератор: не забываем пользоваться кнопочкой "Код"Это сообщение отредактировал(а) bsa - 19.6.2014, 12:27
|