10
« on: December 15, 2009, 03:13:38 pm »
The warning I'm getting is:
"An internal OpenGL call failed in image.cpp (481) : GL_STACK_UNDERFLOW, this com
mand would cause a stack underflow"
The code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <iostream>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#pragma comment(lib, "zdll.lib")
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "sfml-system-d.lib")
#pragma comment(lib, "sfml-window-d.lib")
#pragma comment(lib, "sfml-graphics-d.lib")
#include "grfio.h"
#include "rsm.h"
sf::RenderWindow App;
rsm::file rsm_file;
sf::Font myFont;
sf::String myString;
void initialize()
{
if(!myFont.LoadFromFile("H:\\WINDOWS\\Fonts\\arial.ttf"))
printf("Failed to load font..\n");
myString = sf::String("", myFont, 12);
float cN = 1.0f / 255;
glClearColor(100 * cN, 149 * cN, 237 * cN, 1.0);
App.PreserveOpenGLStates(true);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glClearDepth(1.f);
glCullFace(GL_BACK);
/* get our grf files ready */
char *filenames[1];
filenames[0] = "sdata.grf";
//filenames[1] = "data.grf";
grfio_init(filenames, 1);
/* lets load our first 3d model */
char* fname = "data\\model\\manuk\\¿î¿µÃ».rsm";
rsm_file.filename = fname;
int fsize = 0;
char* fdata = (char*)grfio_reads(fname, &fsize);
if(!rsm::load(rsm_file, fdata, fsize))
printf("rsm: failed <load %s>\n", fname);
}
void shutdown()
{
rsm::dispose(rsm_file);
App.Close();
grfio_final();
}
void changeSize(int w, int h)
{
float ratio = (float)w / h;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, w, h);
gluPerspective(45, ratio, 1, 1000);
}
float angle = 0.0f;
void renderScene(void)
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
gluLookAt(0.0, 20.0,200.0, 0.0,20.0 + 0.0,200.0+-1.0, 0.0f,1.0f,0.0f);
glRotatef((angle += App.GetFrameTime() * 100.0f), 0, 1, 0);
glScalef(1, -1, -1);
rsm::render_rsm(rsm_file);
glPopMatrix();
glPushMatrix();
myString.SetText(rsm_file.filename);
myString.SetPosition(10, 10);
App.Draw(myString);
glPopMatrix();
}
int main(int argc, char **argv)
{
sf::WindowSettings Settings;
Settings.DepthBits = 24;
Settings.StencilBits = 8;
Settings.AntialiasingLevel = 2;
App.Create(sf::VideoMode(640, 480, 32), "RO Engineer", sf::Style::Close, Settings);
changeSize(App.GetWidth(), App.GetHeight());
initialize();
while (App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
shutdown();
if (Event.Type == sf::Event::Resized)
changeSize(Event.Size.Width, Event.Size.Height);
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
App.SetActive();
renderScene();
App.Display();
}
return 0;
}
The important bits:
(That cause the warning)
[ COMMENT 1 ]
if the fallowing code is placed here, then the warning is shown EVERY frame
" glMatrixMode(GL_MODELVIEW);
glLoadIdentity();"
however, if I place the above code where you see [ COMMENT 2 ]
the warning only shows its ugly head once... interesting phenomenon
float angle = 0.0f;
void renderScene(void)
{
// [ COMMENT 1 ]
glPushMatrix();
// [ COMMENT 2 ]
gluLookAt(0.0, 20.0,200.0, 0.0,20.0 + 0.0,200.0+-1.0, 0.0f,1.0f,0.0f);
glRotatef((angle += App.GetFrameTime() * 100.0f), 0, 1, 0);
glScalef(1, -1, -1);
rsm::render_rsm(rsm_file);
glPopMatrix();
glPushMatrix();
myString.SetText(rsm_file.filename);
myString.SetPosition(10, 10);
App.Draw(myString);
glPopMatrix();
}
Of course, it's only appearing(along w/ other conflictions between SFML and my code) when I added the sf::String class; which is defined here
// outside everything
sf::String myString;
// in the initialization function
myString = sf::String("", myFont, 12);
I hope someone know why this warning occures, and might have some insight on how I may prevent it..
[ SIDE QUESTION ]
Also, if I don't use "glMatrixMode(GL_MODELVIEW);" before rendering my 3d stuff, for some reason it conflict with App.Draw() routine, and not render properly.. so I'm forced to add the glMatrixMode(); does anyone know a way around this, or the proper steps I should be taking to use my code around SFML?