I was trying to get a 3d cube on the xcreen, and scaling it.
in one demo, I got the 3d cube fine, on the second one with scaling not.
here is my code:
#include "glapplication.h"
#include <iostream>
#include <stdlib.h>
using namespace std;
GLApplication::GLApplication(int w, int h) : mWidth(h), mHeight(h) {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
cerr << "Unable to init video" << endl;
quit(1);
}
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
if (SDL_SetVideoMode(w, h, 16, SDL_OPENGL) == NULL) {
cerr << "Unable to set video mode" << endl;
quit(1);
}
}
GLApplication::~GLApplication() {}
void GLApplication::quit(int errorcode) {
SDL_Quit();
exit(errorcode);
}
void GLApplication::initGL() {
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_SMOOTH);
}
void GLApplication::reshape(int w, int h) {
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glMatrixMode (GL_MODELVIEW);
}
void GLApplication::drawScene() {
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
static GLfloat intertwined[] =
{0.3, 0.2, 0.1, 80.0, 320.0, 0.0,
1.0, 0.2, 1.0, 180.0, 320.0, 0.0,
1.0, 0.2, 0.2, 180.0, 430.0, 0.0,
1.0, 1.0, 0.2, 80.0, 430.0, 0.0,
0.2, 1.0, 0.2, 100.0, 300.0, 0.0,
0.2, 1.0, 1.0, 200.0, 300.0, 0.0,
0.2, 0.2, 1.0, 200.0, 400.0, 0.0,
0.45, 0.02, 0.65, 100.0, 400.0, 0.0
};
static GLubyte allIndices[] =
{4, 5, 6, 7, 1, 2, 6, 5,
0, 1, 5, 4, 0, 3, 2, 1,
0, 4, 7, 3, 2, 3, 7, 6};
gluLookAt( 0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glScalef(1.0, 2.0, 1.0);
glInterleavedArrays (GL_C3F_V3F, 0, intertwined);
glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, allIndices);
glFlush();
SDL_GL_SwapBuffers();
}
in the main.cpp an instance of GLApplication is created, initGL, reshape and drawScene is called properly.
I just get a black screen
the problem is too, in every sample of code I look, the reshape function is different, and I still dont understand where and when to use glMatrixMode, glOrtho, glFrustum, glLoadIdentity.
the OpenGL Red book doesnt exwplain it sufficiently for me.