Codemasta
05.07.2002, 19:30
Hi!
Habe jetzt mal versucht, OpenGL mit hilfe von SDL zu programmieren. Aber irgendwie wird beim rendern mein dreieck nicht angezeigt. Hier mal die (nach meiner meinung) wichtigen funktionen:
/**
* Name: CVideo::Reshape()
* Desc: Sets the GL Viewport
**/
GLvoid CVideo::Reshape(GLint iWidth, GLint iHeight, GLfloat fFOV)
{
printf("Setting up the Viewport...");
if(iHeight == 0)
iHeight = 1;
glViewport(0, 0, iWidth, iHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fFOV, (float)(iWidth / iHeight), 0.1f, 1000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
printf("done\n");
}
/**
* Name: CVideo::Init()
* Desc: Initiates SDL and OpenGL
**/
GLboolean CVideo::Init(GLint iWidth, GLint iHeight, GLint iDepth, GLuint uiVFlags, char *pszTitle)
{
m_iWidth = iWidth;
m_iHeight = iHeight;
m_iDepth = iDepth;
m_uiVFlags = uiVFlags;
m_pszTitle = pszTitle;
printf("Starting initialisation of SDL and OpenGL..");
if(SDL_Init(SDL_INIT_VIDEO) < 0)
{
printf("Could not initialise SDL: %s\n", SDL_GetError());
return GL_FALSE;
}
printf(".");
if(iDepth == 32)
{
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
}
else if(iDepth == 16)
{
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
}
else
{
printf("The Depth you requested is not supported by SDL");
return GL_FALSE;
}
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
printf(".");
m_pScreen = SDL_SetVideoMode(iWidth, iHeight, 0, uiVFlags);
if(!m_pScreen)
{
printf("Could not set video mode: %s\n", SDL_GetError());
return GL_FALSE;
}
printf(".");
printf("done\n");
SDL_WM_SetCaption(pszTitle, 0);
Reshape(iWidth, iHeight, 45.0f);
return GL_TRUE;
}
void Render(void)
{
video.Clear();
glTranslatef(0.0f, 0.0f, -6.0f);
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 1.0f, 1.0f);
glVertex3f(0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f, 0.0f, 0.0f);
glVertex3f(1.0f, 0.0f, 0.0f);
glEnd();
video.Present();
}
inline GLvoid Clear (void) { ::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ::glLoadIdentity(); }
inline GLvoid Present (void) { ::SDL_GL_SwapBuffers(); }
sorry das das so viel ist ...
Habe jetzt mal versucht, OpenGL mit hilfe von SDL zu programmieren. Aber irgendwie wird beim rendern mein dreieck nicht angezeigt. Hier mal die (nach meiner meinung) wichtigen funktionen:
/**
* Name: CVideo::Reshape()
* Desc: Sets the GL Viewport
**/
GLvoid CVideo::Reshape(GLint iWidth, GLint iHeight, GLfloat fFOV)
{
printf("Setting up the Viewport...");
if(iHeight == 0)
iHeight = 1;
glViewport(0, 0, iWidth, iHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fFOV, (float)(iWidth / iHeight), 0.1f, 1000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
printf("done\n");
}
/**
* Name: CVideo::Init()
* Desc: Initiates SDL and OpenGL
**/
GLboolean CVideo::Init(GLint iWidth, GLint iHeight, GLint iDepth, GLuint uiVFlags, char *pszTitle)
{
m_iWidth = iWidth;
m_iHeight = iHeight;
m_iDepth = iDepth;
m_uiVFlags = uiVFlags;
m_pszTitle = pszTitle;
printf("Starting initialisation of SDL and OpenGL..");
if(SDL_Init(SDL_INIT_VIDEO) < 0)
{
printf("Could not initialise SDL: %s\n", SDL_GetError());
return GL_FALSE;
}
printf(".");
if(iDepth == 32)
{
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
}
else if(iDepth == 16)
{
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
}
else
{
printf("The Depth you requested is not supported by SDL");
return GL_FALSE;
}
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
printf(".");
m_pScreen = SDL_SetVideoMode(iWidth, iHeight, 0, uiVFlags);
if(!m_pScreen)
{
printf("Could not set video mode: %s\n", SDL_GetError());
return GL_FALSE;
}
printf(".");
printf("done\n");
SDL_WM_SetCaption(pszTitle, 0);
Reshape(iWidth, iHeight, 45.0f);
return GL_TRUE;
}
void Render(void)
{
video.Clear();
glTranslatef(0.0f, 0.0f, -6.0f);
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 1.0f, 1.0f);
glVertex3f(0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f, 0.0f, 0.0f);
glVertex3f(1.0f, 0.0f, 0.0f);
glEnd();
video.Present();
}
inline GLvoid Clear (void) { ::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ::glLoadIdentity(); }
inline GLvoid Present (void) { ::SDL_GL_SwapBuffers(); }
sorry das das so viel ist ...