where do i put in my rotate function - c++

#include "std_lib_facilities.h"
#include <GL/glut.h>
static float dx=0.0;
static float dz=10;
static float points[2];
static float cx=0.0;
static float cy=0.0;
static float cz=0.0;
static float spin=0.0;
static float rotation=1.0;
int readObject()
{
ifstream inputFile("spikeBall.ogl");
if(!inputFile)
{
cerr << "cannot open file spikeBall.ogl" << endl;
return -1;
}
int count = 0;
float x,y,z;
do{
inputFile >> count;
glBegin(GL_POLYGON);
for(int i=0;i<count;i++)
{
inputFile >> x >> y >> z;
glVertex3f(((x/5)+cx),((y/5)+cy),((z/5)+cz));
}
glEnd();
}while(count!=0);
inputFile.close();
}
void init(void)
{
glClearColor(0.0,0.0,0.0,0.0);
}
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glLoadIdentity();
gluLookAt (0,0,20, 0.0,0.0,0.0, 0.0,1.0,0.0);
glPushMatrix();
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
GLfloat aMaterial[]={0.1745,0.01175,0.01175,1.0};
GLfloat bMaterial[]={0.61424,0.04136,0.04136,1.0};
GLfloat cMaterial[]={0.727811,0.626959,0.626959,1.0};
GLfloat dMaterial=40;
glMaterialfv(GL_FRONT,GL_AMBIENT,aMaterial);
glMaterialfv(GL_FRONT,GL_DIFFUSE,bMaterial);
glMaterialfv(GL_FRONT,GL_SPECULAR,cMaterial);
glMaterialf(GL_FRONT,GL_SHININESS,dMaterial);
readObject();
glRotatef(spin,0.0,1.0,0.0);
glPopMatrix();
glFlush();
}
void idleFunc(void)
{
spin+=rotation;
if(spin>360.0)
{
spin-=360.0;
}
cz+=0.1;
if(cz==20)
{
srand((unsigned int) time(NULL));
for(int i=0;i<2;i++)
{
points[i] = (rand()%20)-10;
}
cx = points[0];
cy = points[1];
cz = 0;
GLfloat lightPos[] = {cx,cy,(cz+2),1.0};
glLightfv(GL_LIGHT0,GL_POSITION,lightPos);
std::cout << "cx:" << cx;
std::cout << "cy:" << cy;
std::cout << "cz:" << cz;
}
else
{
}
glutPostRedisplay();
}
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0,20.0);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(300,300);
glutInitWindowPosition(0,0);
glutCreateWindow("3ds Max loader");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
init();
glutIdleFunc(idleFunc);
glutMainLoop();
return(0);
}
iat the moment it's just moving forward, i want it to spin too, but everywhere i put it, it's either not spinning or it makes the sphere look like it just blew up ( like when i put it after glEnd())

I would create an update loop where you could call all of your logic functions, and create a new seperate Rotate() function then call it there. The general format for games programming I usually follow is:
main()
{
init();
while(gameOn)
{
update();
draw();
}
}
init()
{
//create textures, etc.
}
update()
{
//do logic
}
draw()
{
//display on screen after update
}

Related

I am trying to use structure in c++ but its not working

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.

OpenGL Glut Drawing Points Not Working

Can someone help me out in checking my code? I'm trying to draw a simple dot by clicking in the window, but I can't see any points drawn. The point recording system is copied as an example from one of the stack overflow posts.
#include <stdlib.h>
#include <stdio.h>
//#include <GL\glew.h>
#include <gl/glut.h>
//#include <GL\freeglut.h>
#include <math.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include "draw.h"
//DRAW draw2;
class Point
{
int Xvalue, Yvalue;
std::string Text;
public:
void xy(int x, int y)
{
Xvalue = x;
Yvalue = y;
}
void text(std::string text)
{
Text = text;
}
//return individual x y value
int x() { return Xvalue; }
int y() { return Yvalue; }
//return text value
std::string rtext() { return Text; }
};
Point point[30];
int count = 0;
void Init()
{
glClearColor(1.0, 1.0, 1.0, 0.0);
//glColor3f(0.0, 0.0, 0.0);
//glPointSize(5);
glMatrixMode(GL_PROJECTION); //coordinate system
//glLoadIdentity();
gluOrtho2D(0.0, 1200.0, 0.0, 800.0);
}
void Display()
{
glClear(GL_COLOR_BUFFER_BIT); // clear display window
glColor3f(1.0, 1.0, 1.0);
//glLoadIdentity();
/*Drawing here*/
//redraw
for (int i = 0; i < count; i++)
{
int x = point[i].x();
int y = point[i].y();
//draw2.Dot(x, y);
std::cout << "drawing dot " << x << " " << y << std::endl;
glBegin(GL_POINTS);
glColor3f(0.3, 0.3, 0.3);
glPointSize(5.0f);
glVertex2i(x, glutGet(GLUT_WINDOW_HEIGHT) - y);
glEnd();
}
glFlush();
}
void mouse(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
point[count].xy(x, y);
//draw2.Dot(x, y);
count++;
}
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv); //initialize toolkit
//Request double buffered true color window with Z-buffer
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB ); //display mode
glutInitWindowSize(1200, 800); //set window size
glutCreateWindow("NURBS Curve"); //open screen window
Init(); //additional initializations
//CALLBACK FUNCTIONS
glutMouseFunc(mouse);
glutDisplayFunc(Display); //send graphics to display window
/*
GLenum err = glewInit();
if (GLEW_OK != err)
{
fprintf(stderr, "GLEW error");
return 1;
}
*/
//pass control to glut for events, loops
glutMainLoop();
return 0;
}
glBegin(GL_POINTS);
glColor3f(0.3, 0.3, 0.3);
glPointSize(5.0f); // wat
glVertex2i(x, glutGet(GLUT_WINDOW_HEIGHT) - y);
glEnd();
There's a short list of GL functions you can call inside a glBegin()/glEnd() pair and glPointSize() is not on it:
Only a subset of GL commands can be used between glBegin and glEnd.
The commands are
glVertex,
glColor,
glSecondaryColor,
glIndex,
glNormal,
glFogCoord,
glTexCoord,
glMultiTexCoord,
glVertexAttrib,
glEvalCoord,
glEvalPoint,
glArrayElement,
glMaterial, and
glEdgeFlag.
Also,
it is acceptable to use
glCallList or
glCallLists to execute
display lists that include only the preceding commands.
If any other GL command is executed between glBegin and glEnd,
the error flag is set and the command is ignored.
Move the glPointSize() outside the glBegin()/glEnd() pair:
glPointSize(5.0f);
glBegin(GL_POINTS);
for (int i = 0; i < count; i++)
{
int x = point[i].x();
int y = point[i].y();
glColor3f(0.3, 0.3, 0.3);
glVertex2i(x, h - y);
}
glEnd();
All together:
#include <gl/glut.h>
class Point
{
int Xvalue, Yvalue;
public:
void xy(int x, int y)
{
Xvalue = x;
Yvalue = y;
}
//return individual x y value
int x() { return Xvalue; }
int y() { return Yvalue; }
};
Point point[30];
int count = 0;
void Display()
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT); // clear display window
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
const double w = glutGet( GLUT_WINDOW_WIDTH );
const double h = glutGet( GLUT_WINDOW_HEIGHT );
gluOrtho2D(0.0, w, 0.0, h);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glColor3f(1.0, 1.0, 1.0);
glPointSize(5.0f);
glBegin(GL_POINTS);
for (int i = 0; i < count; i++)
{
int x = point[i].x();
int y = point[i].y();
glColor3f(0.3, 0.3, 0.3);
glVertex2i(x, h - y);
}
glEnd();
glFlush();
}
void mouse(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
point[count].xy(x, y);
count++;
}
glutPostRedisplay();
}
int main( int argc, char *argv[] )
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB );
glutInitWindowSize(1200, 800);
glutCreateWindow("NURBS Curve");
glutMouseFunc(mouse);
glutDisplayFunc(Display);
glutMainLoop();
return 0;
}
Found out that glcolor3f and glpointsize had to be initialized first in my Init() function.
void Init()
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glColor3f(0.0, 0.0, 0.0); //this one
glPointSize(5); //and this one
glMatrixMode(GL_PROJECTION); //coordinate system
//glLoadIdentity();
gluOrtho2D(0.0, 1200.0, 0.0, 800.0);
}

My Shape does not want to move when press a key on OPENGL

I want to make the shape perform a jump while moving horizontally using the sin function but it does not even respond to the 'j' button when it is pressed ?
Am still learning Opengl thouh. Any help about where is the mistake?
#include <GLUT/glut.h>
#include <math.h>
float pointone = 0;
float ydir =0;
GLboolean turn ;
void Display();
void DrawWall();
void Anim();
void Keyboard(unsigned char key, int x, int y);
int main(int argc, char** argr) {
glutInit(&argc, argr);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(1000, 600);
glutInitWindowPosition(50, 50);
glutKeyboardFunc(Keyboard);
glutIdleFunc(Anim);
glutCreateWindow("Kbeer El Haramiya");
glutDisplayFunc(Display);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glPointSize(20.0);
gluOrtho2D(0.0, 1000.0, 0.0, 600.0);
glutMainLoop();
}
void Display() {
glClear(GL_COLOR_BUFFER_BIT);
DrawWall();
glPushMatrix();
if(pointone<=850 && turn ==true){
pointone+=3;
turn=true;}
else if (pointone==0){
turn=true;}
else {
turn = false;
pointone-=3;
}
glTranslatef(pointone, ydir, 0);
glBegin(GL_POLYGON);
glColor3f(0.97f,0.96f,0.768f);
glVertex2i(0.0f, 0.0f);
glVertex2i(50.0f, 0.0f);
glVertex2i(50.0f, 50.0f);
glColor3f(0.70f,0.196f,0.12f);
glVertex2i(0.0f, 50.0f);
glEnd();
glPopMatrix();
glFlush();
}
void DrawWall(){
glBegin(GL_POLYGON);
glColor3f(0.97f,0.96f,0.768f);
glVertex2i(999, 0);
glVertex2i(999,600);
glVertex2i(900, 600);
glVertex2i(900, 0);
glEnd();
glBegin(GL_POLYGON);
glVertex2i(0, 200);
glVertex2i(700,200);
glVertex2i(700, 150);
glVertex2i(0,150);
glEnd();
}
void Keyboard(unsigned char key, int x, int y){
if(key == 'j') {
for(int i =0; i<361;i++){
ydir =sin(i);
glutPostRedisplay();
}
}
}
void Anim(){
glutPostRedisplay();
}
You have to update ydir somewhere in the Display() function. When you try to update it outside of this in a loop, there is only one single redraw scheduled after the Keyboard function has ended.
The code could look (for example) somehow like this:
int yint = -1; //-1 means no moving
void Display() {
if (yint > 360) // Reset when > 360°
yint = -1;
if (yint >= 0 && yint <= 360) //Update until 360° is reached
yint++;
float ydir = sin(yint);
//Draw code here
}
void Keyboard(unsigned char key, int x, int y){
if(key == 'j')
yint = 0;
}
The solution was simple, I was supposed to Create the window before calling Keyboardfunc ! :)

Keyboard input doesn't work, works when clicking the mouse

I have this code:
#include <iostream>
#include <GL/glut.h>
using namespace std;
bool* Keys = new bool[256];
void keyboardDown(unsigned char key, int x, int y)
{
Keys[key] = true;
}
void keyboardUp(unsigned char key, int x, int y)
{
Keys[key] = false;
}
void reshape(int width, int height)
{
GLfloat fieldOfView = 90.0f;
glViewport(0, 0, (GLsizei)width, (GLsizei)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fieldOfView, (GLfloat)width / (GLfloat)height, 0.1, 500.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void draw()
{
if (Keys['e'])
cout << "e" << endl;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBegin(GL_QUADS);
glColor3f(0.1, 0.1, 0.1); glVertex3f(1.0, 1.0, -1.0);
glColor3f(0.1, 0.9, 0.1); glVertex3f(1.0, -1.0, -1.0);
glColor3f(0.9, 0.1, 0.1); glVertex3f(-1.0, -1.0, -1.0);
glColor3f(0.1, 0.1, 0.9); glVertex3f(-1.0, 1.0, -1.0);
glEnd();
glFlush();
glutSwapBuffers();
}
void initGL(int width, int height)
{
reshape(width, height);
glClearColor(0.1f, 0.5f, 0.7f, 1.0f);
glClearDepth(1.0f);
glOrtho(0, 1, 0, 1, 1, 10);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
}
/* initialize GLUT settings, register callbacks, enter main loop */
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(800, 800);
glutInitWindowPosition(100, 100);
glutCreateWindow("Perspective's GLUT Template");
glutKeyboardFunc(keyboardDown);
glutKeyboardUpFunc(keyboardUp);
glutSpecialFunc(keyboardSpecialDown);
glutSpecialUpFunc(keyboardSpecialUp);
glutReshapeFunc(reshape);
glutDisplayFunc(draw);
glutIgnoreKeyRepeat(true); // ignore keys held down
initGL(800, 600);
glutMainLoop();
return 0;
}
When I start the program, it writes 'e' only when I press on the mouse. I can't find the problem. Why does it only work when the mouse is held down?
You dont have mouse functions in your code, thats why it is not working. Insert from here : http://www.zeuscmd.com/tutorials/glut/03-MouseInput.php
#include <iostream>
#include <gl/glut.h>
using namespace std;
bool lbuttonDown = false;
bool init()
{
return true;
}
void display()
{
}
void mouse(int button, int state, int x, int y)
{
if (button == GLUT_RIGHT_BUTTON)
{
if (state == GLUT_DOWN)
cout << "Right button pressed"
<< endl;
else
cout << "Right button lifted "
<< "at (" << x << "," << y
<< ")" << endl;
}
else if (button == GLUT_LEFT_BUTTON)
{
if (state == GLUT_DOWN)
lbuttonDown = true;
else
lbuttonDown = false;
}
}
void motion(int x, int y)
{
if (lbuttonDown)
cout << "Mouse dragged with left button at "
<< "(" << x << "," << y << ")" << endl;
}
void motionPassive(int x, int y)
{
cout << "Mouse moved at "
<< "(" << x << "," << y << ")" << endl;
}
void entry(int state)
{
if (state == GLUT_ENTERED)
cout << "Mouse Entered" << endl;
else
cout << "Mouse Left" << endl;
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowPosition(200, 200);
glutInitWindowSize(200, 200);
glutCreateWindow("03 - Mouse Input");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutPassiveMotionFunc(motionPassive);
glutEntryFunc(entry);
if (!init())
return 1;
glutMainLoop();
return 0;
}
I had the same problem [using freeglut] and calling 'draw()' [or whatever display callback you use] right after glutPostRedisplay() in the key callback function forced it to do the redraw. I actually don't know why it behaves like this. After data is changed by keyboard input and the key callback returned, a redraw is expected but not executed.

opengl not drawing anything

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.