#include "stdafx.h"
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include "glut.h"
int winWidth = 700;
int winHeight = 600;
void init() {
glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, winWidth, 0.0, winHeight);
}
void renderSpacedBitmapString(float x, float y, void *font, char *string) {
char *c;
int x1 = x;
for (c = string; *c != '\0'; c++) {
glRasterPos2f(x1, y);
glutBitmapCharacter(font, *c);
x1 = x1 + glutBitmapWidth(font, *c);
}
}
void draw_text() {
glColor3f(255.0, 0, 0.0); /* red color */
char buf[100] = { 0 };
sprintf_s(buf, "DO YOU WANT TO GO TO SPACE?");
renderSpacedBitmapString(15, 600, GLUT_BITMAP_HELVETICA_18, buf);
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT);
draw_text();
glFlush();
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(winWidth, winHeight);
glutInitWindowPosition(100, 100);
glutCreateWindow("Drawn Text");
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
I have this problem where I can't make the text appear on the screen, however when I change the gluOrtho2D code to gluOrtho2D(-200.0, 800, -200.0, 800); it starts to work, but I want to keep the gluOrtho2D code the same as above, and I don't want to change it.
y = 600 is just a bit above your gluOrtho2D() clip volume. Drop the string down a bit (passing 580 into the y argument of renderSpacedBitmapString() works) or increase the window height (620 works).
I am following the tutorial "Making Games With Bens" (https://www.youtube.com/user/makinggameswithben) on OpenGL and I get this
missing gl version
every time I try to initialize glew.
I have reinstalled glew and SDL2 many times.
I don't understand what I'm doing wrong.
I am using glew 2.0.0 and SDL2 2.0.5
headerfile:
#pragma once
#include <string>
#include <vector>
//Graphics
#include <SDL2\SDL.h>
#include <GL\glew.h>
class Display
{
public://functions:
Display(int m_width, int m_heigth, const char title []);
void update();
~Display();
private:
public://variables:
std::vector<char> error;
int width;
int heigth;
private:
//Window pointer
SDL_Window * m_window;
};
.cpp file:
#include "Display.h"
Display::Display(int m_width, int m_heigth, const char title[])
{
m_window = nullptr;
width = m_width;
heigth = m_heigth;
//Initialize SDL
SDL_Init(SDL_INIT_EVERYTHING);
m_window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, m_width, m_heigth, SDL_WINDOW_OPENGL);
//error 1:
if (m_window = nullptr) {
error.push_back(255);
}
//error 2:
SDL_GLContext glContext = SDL_GL_CreateContext(m_window);
if (glContext = nullptr) {
error.push_back(254);
}
const GLenum GLerror = glewInit();
//error 3:
if (GLerror != GLEW_OK) {
error.push_back(GLerror);
}
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
}
void Display::update()
{
glClearDepth(1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
SDL_GL_SwapWindow(m_window);
}
Display::~Display()
{
delete m_window;
SDL_Quit();
}
You may have to do:
glewExperimental = GL_TRUE;
right before
glewInit();
This will allow GLEW to use OpenGL features above OpenGL version 2.0.
in this method
void Sierpinski(GLintPoint points) {
glClear(GL_COLOR_BUFFER_BIT);
GLintPoint T[3] = {{10,10},{600,10},{300,600}};
int index=rand()%3;
GLintPoint point=points[index];
drawDot(point.x, point.y);
for (int i = 0;i<55000;i++) {
index=rand()%3;
point.x=(point.x+points[index].x)/2;
point.y=(point.y+points[index].y)/2;
drawDot(point.x,point.y);
}
glFlush();
}
that uses the structure i made
struct GLintPoint {
GLint x,y;
};
it says that there is an error and that "no operator "[]" matches these operands, operator types are GLintPoint[int]" where i try to assign a value from points to point. Well i did use the right brackets and it is an int in there so what is the problem? FYI this code is to draw the Sierpinski gasket with the user making the initial 3 points by clicking the screen with the mouse. Just in case you would like to see it here is the whole program.
#include <windows.h>
#include <gl/Gl.h>
#include "glut.h"
#include <iostream>
using namespace std;
const int screenWidth = 640;
const int screenHeight = 480;
struct GLintPoint {
GLint x,y;
};
void display (void){
glClear(GL_COLOR_BUFFER_BIT);
//glColor3f(1.0,1.0,1.0);
glFlush();
}
void drawDot( GLint x, GLint y)
{
glBegin( GL_POINTS );
glVertex2i( x, y );
glEnd();
}
void Sierpinski(GLintPoint points) {
glClear(GL_COLOR_BUFFER_BIT);
GLintPoint T[3] = {{10,10},{600,10},{300,600}};
int index=rand()%3;
GLintPoint point=points[index];
drawDot(point.x, point.y);
for (int i = 0;i<55000;i++) {
index=rand()%3;
point.x=(point.x+points[index].x)/2;
point.y=(point.y+points[index].y)/2;
drawDot(point.x,point.y);
}
glFlush();
}
void myMouse(int button, int state, int x, int y){
static GLintPoint corner[2];
static int numCorners = 0;
if(state == GLUT_DOWN){
if(button == GLUT_LEFT_BUTTON){
corner[numCorners].x = x;
corner[numCorners].y = screenHeight - y;
if(++numCorners ==2 ){
glRecti(corner[0].x, corner[0].y, corner[1].x, corner[1].y);
numCorners = 0;
glFlush();
}
}
else if(button == GLUT_RIGHT_BUTTON){
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
}
}
void myInit() {
glClearColor(1.0,1.0,1.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0f,0.0f,0.0f);
glPointSize(2.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, (GLdouble)screenWidth, 0.0, (GLdouble)screenHeight);
}
void main (int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(screenWidth, screenHeight);
glutInitWindowPosition(100,150);
glutCreateWindow("mouse dots");
glutDisplayFunc(display);
glutPostRedisplay();
glutMouseFunc(myMouse);
myInit();
glutMainLoop();
}
I'm inferring from the name of the function argument, points, that you intend the function to accept an array of points. But it's actually just written to take one.
So when you write points[index] the compiler is looking for operator[] in your GLintPoint struct (and there isn't one).
If you change the function prototype to take an array of GLintPoints I think you'll have better luck.
Im trying to convert an OpenCV-codesample, which i found on the internet, from the old IplImage-Format to the currently used Mat-Format, but im inexperienced regarding the correct use of pointers/classes and hope someone can help me convert the few codelines. The code mainly initializes a webcam, grabs the frames und displays them via OpenGL.
The mentioned difficult code:
CvCapture *cvCapture = 0;
cvCapture = cvCreateCameraCapture(0);
IplImage* newImage = cvQueryFrame( cvCapture );
cvReleaseCapture( &cvCapture );
I tried:
cv::VideoCapture *cvCapture = 0;
cvCapture.open(0);
cvCapture.read(cv:Mat& newImage);
cvCapture.release;
Original Code:
#ifdef WIN32
#include <windows.h>
#endif
#include <stdio.h>
#include <gl/glew.h>
#include <gl/glut.h>
#include <opencv/highgui.h>
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// GLUT callbacks and functions
void initGlut(int argc, char **argv);
void displayFunc(void);
void idleFunc(void);
void reshapeFunc(int width, int height);
void mouseFunc(int button, int state, int x, int y);
void mouseMotionFunc(int x, int y);
void keyboardFunc(unsigned char key, int x, int y);
void specialFunc(int key, int x, int y);
//-----------------------------------------------------------------------------
// other [OpenGL] functions
void countFrames(void);
void renderBitmapString(float x, float y, float z, void *font, char *string);
//-----------------------------------------------------------------------------
bool bFullsreen = false;
int nWindowID;
//-----------------------------------------------------------------------------
// parameters for the framecounter
char pixelstring[30];
int cframe = 0;
int time = 0;
int timebase = 0;
//-----------------------------------------------------------------------------
// OpenCV variables
CvCapture *cvCapture = 0;
GLuint cameraImageTextureID;
//-----------------------------------------------------------------------------
bool bInit = false;
//-----------------------------------------------------------------------------
void displayFunc(void) {
if(!bInit) {
// initialize 1st camera on the bus
cvCapture = cvCreateCameraCapture(0);
// initialze OpenGL texture
glEnable(GL_TEXTURE_RECTANGLE_ARB);
glGenTextures(1, &cameraImageTextureID);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, cameraImageTextureID);
glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
bInit = true;
}
IplImage* newImage = cvQueryFrame( cvCapture );
if( (newImage->width > 0) && (newImage->height > 0)) {
// clear the buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glEnable(GL_TEXTURE_RECTANGLE_ARB);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,(GLdouble)newImage->width,0.0,(GLdouble)newImage->height);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, cameraImageTextureID);
if(newImage->nChannels == 3)
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB, newImage->width, newImage->height, 0,
GL_BGR, GL_UNSIGNED_BYTE, newImage->imageData);
else if(newImage->nChannels == 4)
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, newImage->width, newImage->height,
0, GL_BGRA, GL_UNSIGNED_BYTE, newImage->imageData);
glBegin(GL_QUADS);
glTexCoord2i(0,0);
glVertex2i(0,0);
glTexCoord2i(newImage->width,0);
glVertex2i(newImage->width,0);
glTexCoord2i(newImage->width,newImage->height);
glVertex2i(newImage->width,newImage->height);
glTexCoord2i(0,newImage->height);
glVertex2i(0,newImage->height);
glEnd();
}
glDisable(GL_TEXTURE_RECTANGLE_ARB);
countFrames();
glutSwapBuffers();
}
//-----------------------------------------------------------------------------
void initGlut(int argc, char **argv) {
// GLUT Window Initialization:
glutInit (&argc, argv);
glutInitWindowSize (640, 480);
glutInitWindowPosition(300, 100);
glutInitDisplayMode ( GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
nWindowID = glutCreateWindow ("simpleGLUT - CvCamera");
// Register callbacks:
glutDisplayFunc (displayFunc);
glutReshapeFunc (reshapeFunc);
glutKeyboardFunc (keyboardFunc);
glutSpecialFunc (specialFunc);
glutMouseFunc (mouseFunc);
glutMotionFunc (mouseMotionFunc);
glutIdleFunc (idleFunc);
}
//-----------------------------------------------------------------------------
void idleFunc(void) {
glutPostRedisplay();
}
//-----------------------------------------------------------------------------
void reshapeFunc(int width, int height) {
glViewport(0, 0, width, height);
}
//-----------------------------------------------------------------------------
// mouse callback
void mouseFunc(int button, int state, int x, int y) {
}
//-----------------------------------------------------------------------------
void mouseMotionFunc(int x, int y) {
}
//-----------------------------------------------------------------------------
void keyboardFunc(unsigned char key, int x, int y) {
switch(key) {
// -----------------------------------------
#ifdef WIN32
// exit on escape
case '\033':
if(bInit) {
glDeleteTextures(1, &cameraImageTextureID);
cvReleaseCapture( &cvCapture );
}
exit(0);
break;
#endif
// -----------------------------------------
// switch to fullscreen
case 'f':
bFullsreen = !bFullsreen;
if(bFullsreen)
glutFullScreen();
else {
glutSetWindow(nWindowID);
glutPositionWindow(100, 100);
glutReshapeWindow(640, 480);
}
break;
// -----------------------------------------
}
}
//-----------------------------------------------------------------------------
void specialFunc(int key, int x, int y) {
//printf("key pressed: %d\n", key);
}
//-----------------------------------------------------------------------------
void countFrames(void) {
time=glutGet(GLUT_ELAPSED_TIME);
cframe++;
if (time - timebase > 50) {
sprintf(pixelstring, "fps: %4.2f", cframe*1000.0/(time-timebase));
timebase = time;
cframe = 0;
// Draw status text and uni-logo:
}
glDisable(GL_LIGHTING);
glColor4f(1.0,1.0,1.0,1.0);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0, 200, 0, 200);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
// render the string
renderBitmapString(5,5,0.0,GLUT_BITMAP_HELVETICA_10,pixelstring);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}
//-----------------------------------------------------------------------------
void renderBitmapString(float x, float y, float z, void *font, char *string) {
char *c;
glRasterPos3f(x, y,z);
for (c=string; *c != '\0'; c++) {
glutBitmapCharacter(font, *c);
}
}
//-----------------------------------------------------------------------------
void main(int argc, char **argv) {
initGlut(argc, argv);
glutMainLoop();
}
Solved my own problem. Also had to change old code like: newImage->width and newImage->nChannels. Dont know how stable the code is, but maybe someone can use it:
#ifdef WIN32
#include <windows.h>
#endif
#include <stdio.h>
#include <gl/glew.h>
#include <gl/glut.h>
#include <opencv/highgui.h>
#include <opencv2\highgui.hpp>
#include <opencv2\core.hpp>
//-----------------------------------------------------------------------------
// GLUT callbacks and functions
void initGlut(int argc, char **argv);
void displayFunc(void);
void idleFunc(void);
void reshapeFunc(int width, int height);
void mouseFunc(int button, int state, int x, int y);
void mouseMotionFunc(int x, int y);
void keyboardFunc(unsigned char key, int x, int y);
void specialFunc(int key, int x, int y);
//-----------------------------------------------------------------------------
// other [OpenGL] functions
void countFrames(void);
void renderBitmapString(float x, float y, float z, void *font, char *string);
//-----------------------------------------------------------------------------
bool bFullsreen = false;
int nWindowID;
//-----------------------------------------------------------------------------
// parameters for the framecounter
char pixelstring[30];
int cframe = 0;
int time = 0;
int timebase = 0;
//-----------------------------------------------------------------------------
// OpenCV variables
cv::VideoCapture cap(0);
GLuint cameraImageTextureID;
//-----------------------------------------------------------------------------
bool bInit = false;
//-----------------------------------------------------------------------------
void displayFunc(void) {
if(!bInit) {
// initialize 1st camera on the bus
// initialze OpenGL texture
glEnable(GL_TEXTURE_RECTANGLE_ARB);
glGenTextures(1, &cameraImageTextureID);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, cameraImageTextureID);
glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
bInit = true;
}
cv::Mat newImage;
cap.read(newImage);
int rows = newImage.rows;
int cols = newImage.cols;
cv::Size s = newImage.size();
rows = s.height;
cols = s.width;
if( (s.width > 0) && (s.height > 0)) {
// clear the buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glEnable(GL_TEXTURE_RECTANGLE_ARB);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,(GLdouble)s.width,0.0,(GLdouble)s.height);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, cameraImageTextureID);
if(newImage.channels() == 3)
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB, s.width, s.height, 0, GL_BGR,
GL_UNSIGNED_BYTE, newImage.data);
else if(newImage.channels() == 4)
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, s.width, s.height, 0, GL_BGRA,
GL_UNSIGNED_BYTE, newImage.data);
glBegin(GL_QUADS);
glTexCoord2i(0,0);
glVertex2i(0,0);
glTexCoord2i(s.width,0);
glVertex2i(s.width,0);
glTexCoord2i(s.width,s.height);
glVertex2i(s.width,s.height);
glTexCoord2i(0,s.height);
glVertex2i(0,s.height);
glEnd();
}
glDisable(GL_TEXTURE_RECTANGLE_ARB);
countFrames();
glutSwapBuffers();
}
void idleFunc(void) {
glutPostRedisplay();
}
void reshapeFunc(int width, int height) {
glViewport(0, 0, width, height);
}
void mouseFunc(int button, int state, int x, int y) {
}
void mouseMotionFunc(int x, int y) {
}
void keyboardFunc(unsigned char key, int x, int y) {
switch(key) {
// exit on escape
case '\033':
if(bInit) {
glDeleteTextures(1, &cameraImageTextureID);
cap.release();
}
exit(0);
break;
// switch to fullscreen
case 'f':
bFullsreen = !bFullsreen;
if(bFullsreen)
glutFullScreen();
else {
glutSetWindow(nWindowID);
glutPositionWindow(100, 100);
glutReshapeWindow(640, 480);
}
break;
}
}
void specialFunc(int key, int x, int y) {
//printf("key pressed: %d\n", key);
}
void countFrames(void) {
time=glutGet(GLUT_ELAPSED_TIME);
cframe++;
if (time - timebase > 50) {
sprintf(pixelstring, "fps: %4.2f", cframe*1000.0/(time-timebase));
timebase = time;
cframe = 0;
// Draw status text and uni-logo:
}
glDisable(GL_LIGHTING);
glColor4f(1.0,1.0,1.0,1.0);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0, 200, 0, 200);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
// render the string
renderBitmapString(5,5,0.0,GLUT_BITMAP_HELVETICA_10,pixelstring);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}
void renderBitmapString(float x, float y, float z, void *font, char *string) {
char *c;
glRasterPos3f(x, y,z);
for (c=string; *c != '\0'; c++) {
glutBitmapCharacter(font, *c);
}
}
void main(int argc, char **argv) {
glutInit (&argc, argv);
glutInitWindowSize (640, 480);
glutInitWindowPosition(300, 100);
glutInitDisplayMode ( GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
nWindowID = glutCreateWindow ("simpleGLUT - CvCamera");
// Register callbacks:
glutDisplayFunc (displayFunc);
glutReshapeFunc (reshapeFunc);
glutKeyboardFunc (keyboardFunc);
glutSpecialFunc (specialFunc);
glutMouseFunc (mouseFunc);
glutMotionFunc (mouseMotionFunc);
glutIdleFunc (idleFunc);
glutMainLoop();
}
Just trying to draw a point using glut and glew for opengl version 4.3
my code
void Renderer(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
glPointSize(100);
glColor3f(255, 0, 0);
glVertex3d(10, 10, 0);
glEnd();
glFlush();
glutSwapBuffers();
}
is not rendering anything, can someone tell me what did i miss? here is full code:
#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;
}
glutInitContextVersion(4, 3);
glutInitContextProfile(GLUT_CORE_PROFILE);
You have requested a Core context. You need to:
Specify a vertex and fragment shader. There are no freebies in Core.
Stop using deprecated functionality like glBegin() and glMatrixMode().
Start using VBOs to submit your geometry.
Start using glDrawArrays() and friends to draw your geometry.