Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML annoying warning, in SFML "GL_STACK_UNDERFLOW"  (Read 2259 times)

0 Members and 1 Guest are viewing this topic.

ninjamint

  • Newbie
  • *
  • Posts: 15
    • View Profile
SFML annoying warning, in SFML "GL_STACK_UNDERFLOW"
« 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:
Code: [Select]

#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

Code: [Select]

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
Code: [Select]

// 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
SFML annoying warning, in SFML "GL_STACK_UNDERFLOW"
« Reply #1 on: December 15, 2009, 03:28:07 pm »
When you call glPushMatrix or glPopMatrix, you don't know which matrix you push/pop. If SFML changes the current matrix mode, you may even end up popping another matrix that the one you pushed. I think that this is what happens when the warning shows up.

You should always call glMatrixMode before calling any function operating on matrices.
Laurent Gomila - SFML developer

ninjamint

  • Newbie
  • *
  • Posts: 15
    • View Profile
SFML annoying warning, in SFML "GL_STACK_UNDERFLOW"
« Reply #2 on: December 15, 2009, 04:15:14 pm »
alright, thanks, doesn't help me solve the warning, but I'll head your instructions and remember using MatrixMode during the appropriate protocols, this isn't to much of a problem, and so I'm hoping you or someone else will read this message, so I can avoid making a new topic..


I'm attempting to draw a model, and then store the rendered screen into a texture, so I can draw it as a sprite(this way I can render several models, aligned to a grid on some GUI interface);

I tried using RenderImage, but even though in visual c++ when I type sf:: and the little window w/ all the different objects shows up and clearly says 'sf::RenderImage' exist, im getting compiler errors saying sf::RenderImage is not defined... imagine that, how would I go about rendering to a texture, if not RenderImage?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
SFML annoying warning, in SFML "GL_STACK_UNDERFLOW"
« Reply #3 on: December 15, 2009, 08:28:28 pm »
Quote
alright, thanks, doesn't help me solve the warning

Are you sure? Can you show your corrected code?
It looked so obvious... :P

Quote
I tried using RenderImage, but even though in visual c++ when I type sf:: and the little window w/ all the different objects shows up and clearly says 'sf::RenderImage' exist, im getting compiler errors saying sf::RenderImage is not defined...

Which branch and revision of SFML are you using? Can you show the exact error message?
Laurent Gomila - SFML developer