Pisze prosty renderer w OpenGL i chcę całą mechanikę upchnąć w osobnej klasie. Gdy wszystko jest w mainie i funkcjach w głównym pliku, działa bez problemu, niestety z osobną klasą już nie.
Kod w wersji main only:
#include "stdafx.h"
#include <GL/glut.h>
void draw()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0, 0.0, 1.0);
//drawing
glLineWidth(1);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(-0.5, 0);
glVertex2f(0, 0);
glVertex2f(0.5, 0);
glVertex2f(0, 0.5);
glVertex2f(0, 0.5);
glEnd();
glFlush();
};
void reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1, 1, -1, 1);
glMatrixMode(GL_MODELVIEW);
};
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(1200, 700);
glutInitWindowPosition(100, 5);
glutInitDisplayMode(GLUT_RGB);
glutCreateWindow("3ds");
glutReshapeFunc(reshape);
glutDisplayFunc(draw);
glClearColor(0, 0, 0, 0);
glutMainLoop();
};
Opengl_renderer.h
#ifndef Opengl_renderer_h
#define Opengl_renderer_h
#include <GL/glut.h>
class Opengl_renderer
{
public:
void reshape(int width, int height);
void draw();
void render(int *argcp, char **argv);
};
#endif
Opengl_renderer.cpp
#include "stdafx.h"
#include "Opengl_renderer.h"
void Opengl_renderer::reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1, 1, -1, 1);
glMatrixMode(GL_MODELVIEW);
};
void Opengl_renderer::draw()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0, 0.0, 0.1);
//drawing
glLineWidth(1);
glBegin(GL_LINES);
glVertex2f(0, 0.5);
glVertex2f(0, -0.5);
glEnd();
glFlush();
};
void Opengl_renderer::render(int *argcp, char **argv)
{
glutInit(argcp, argv);
glutInitWindowSize(1200, 700);
glutInitWindowPosition(100, 5);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
glutCreateWindow("3ds");
glutReshapeFunc(reshape);
glutDisplayFunc(draw);
};
Problem dotyczy wywołań funkcji
glutReshapeFunc(reshape) oraz glutDisplayFunc(draw).
W sytuacji gdy wszystko mam w mainie bez problemu mogę przekazać reshape i draw jako argument, niestety w osobnej klasie to nie działa. Co z tym zrobić?