OpenGL ничего не рисуя

0

Просто пытаюсь нарисовать точку, используя перегиб и glew для opengl версии 4.3

мой код

void Renderer(void)
{ 
    glClear(GL_COLOR_BUFFER_BIT);

    glBegin(GL_POINTS);
    glPointSize(100);
    glColor3f(255, 0, 0);
    glVertex3d(10, 10, 0);
    glEnd();

    glFlush();
    glutSwapBuffers();
}

ничего не делает, может кто-нибудь сказать мне, что я пропустил? вот полный код:

#include <iostream>
using namespace std;

#include "vgl.h"
#include "LoadShaders.h"

enum VAO_IDs { Triangles, NumVAOS };

#define WIDTH 1024
#define HEIGHT 768
#define REFRESH_DELAY     10 //ms

//general
long frameCount = 0;

// mouse controls
int mouse_old_x, mouse_old_y;
int mouse_buttons = 0;
float rotate_x = 0.0, rotate_y = 0.0;
float translate_z = -3.0;

/////////////////////////////////////////////////////////////////////
//! Prototypes
/////////////////////////////////////////////////////////////////////
void keyboard(unsigned char key, int x, int y);
void mouse(int button, int state, int x, int y);
void motion(int x, int y);

void timerEvent(int value)
{
    glutPostRedisplay();
    glutTimerFunc(REFRESH_DELAY, timerEvent, frameCount++);
}

void init (void)
{
    // default initialization
    glClearColor(0.0, 0.0, 0.0, 1.0);
    glDisable(GL_DEPTH_TEST);

    // viewport
    glViewport(0, 0, WIDTH, HEIGHT);

    // projection
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60.0, (GLfloat)WIDTH / (GLfloat)HEIGHT, 1, 10000.0);
}

void Renderer(void)
{ 
    glClear(GL_COLOR_BUFFER_BIT);

    glBegin(GL_POINTS);
    glPointSize(100);
    glColor3f(255, 0, 0);
    glVertex3d(10, 10, 0);
    glEnd();

    glFlush();
    glutSwapBuffers();
}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA);
    glutInitWindowSize(WIDTH, HEIGHT);
    glutInitContextVersion(4, 3);
    glutInitContextProfile(GLUT_CORE_PROFILE);
    glutCreateWindow("The Abyss");
    glutKeyboardFunc(keyboard);
    glutMotionFunc(motion);
    glutMouseFunc(mouse);

    glutTimerFunc(REFRESH_DELAY, timerEvent, frameCount);

    if (glewInit()) //i guess this is true on failure
    {
        cerr << "Error initializing glew, Program aborted." << endl;
        exit(EXIT_FAILURE);
    }


    //Init First
    init();

    //Init callback for Rendering
    glutDisplayFunc(Renderer);

    //Main Loop
    glutMainLoop();

    exit(EXIT_SUCCESS);
}

////////////////////////////////////////////////////////////////////////
//!Mouse and keyboard functionality
////////////////////////////////////////////////////////////////////////
void keyboard(unsigned char key, int /*x*/, int /*y*/)
{
    switch (key)
    {
        case (27) :
            exit(EXIT_SUCCESS);
            break;
    }
}

void mouse(int button, int state, int x, int y)
{
    if (state == GLUT_DOWN)
    {
        mouse_buttons |= 1<<button;
    }
    else if (state == GLUT_UP)
    {
        mouse_buttons = 0;
    }

    mouse_old_x = x;
    mouse_old_y = y;
}

void motion(int x, int y)
{
    float dx, dy;
    dx = (float)(x - mouse_old_x);
    dy = (float)(y - mouse_old_y);

    if (mouse_buttons & 1)
    {
        rotate_x += dy * 0.2f;
        rotate_y += dx * 0.2f;
    }
    else if (mouse_buttons & 4)
    {
        translate_z += dy * 0.01f;
    }

    mouse_old_x = x;
    mouse_old_y = y;
}
Теги:
opengl

1 ответ

2
glutInitContextVersion(4, 3);
glutInitContextProfile(GLUT_CORE_PROFILE);

Вы запросили основной контекст. Тебе нужно:

  1. Укажите шейдер вершин и фрагментов. В Core нет бесплатной подписки.
  2. Прекратите использование устаревших функций, таких как glBegin() и glMatrixMode().
  3. Начните использовать VBOs, чтобы представить свою геометрию.
  4. Начните использовать glDrawArrays() и друзей, чтобы нарисовать вашу геометрию.
  • 0
    Для уточнения - все перечисленные функции полностью недоступны в профиле ядра с указанной версией и приведут к ошибке GL. Либо так, либо используйте профиль совместимости.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню