Note that there are some explanatory texts on larger screens.

plurals
  1. POSDL OpenGL Rendering Issue
    primarykey
    data
    text
    <p>I am just learning how to use SDL and openGL. I've been through the tutorials over at SDLTutorials.com. I am now trying to take things further and create a loading screen for an application; an oop menu system. </p> <p>I am starting off real simple to test things out. I have the main backdrop of the window done via a texture class. The two relevant functions are defined here:</p> <pre><code>void Texture::Bind() { glBindTexture(GL_TEXTURE_2D, TextureID); } void Texture::RenderQuad(int X, int Y, int Width, int Height) { Bind(); glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex3f(X, Y, 0); glTexCoord2f(1, 0); glVertex3f(X + Width, Y, 0); glTexCoord2f(1, 1); glVertex3f(X + Width, Y + Height, 0); glTexCoord2f(0, 1); glVertex3f(X, Y + Height, 0); glEnd(); } </code></pre> <p>I also have created a menu class that will basically be the parent of any menu created in the system and classes to be developed would be like a click button or an edit box. So far, the only relevent function in class Menu is:</p> <pre><code>void Menu::OnRender() { if( Visible ) { if(MenuTexture == NULL) { glColor4f(1.,G,B,A); glBegin(GL_QUADS); glVertex2d(X, Y); glVertex2d(X+Width,Y); glVertex2d(X+Width,Y+Height); glVertex2d(X,Y+Height); glEnd(); }else{ MenuTexture-&gt;RenderQuad(X,Y,Width,Height); } } } </code></pre> <p>Finally, my application has created one texture that it binds to the whole window. i.e. the backround. </p> <pre><code>void App::OnRender() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); MainScreen.RenderQuad(0,0,winWidth,winHeight); //Texture Object with bkg.jpg MainMenu.OnRender(); //Menu object to be 150x300 and all black SDL_GL_SwapBuffers(); } </code></pre> <p>I then create a menu item and try to draw it over the backdrop. If I leave the initialized colors black, the entire screen turns black almost instantly: I have one frame probably the first cycle through where the menu is drawn, the black square is placed on the window, and then it turns black.. If I have 1.0 for the Red, then the entire picture has like some sort of red filter placed on it and the menu box draws an opaque red square. </p> <p>I've been through several examples of how rendering but I must be missing something. Essentially, if we put it all in line of whats being done, I bind the texture to a surface, define the coordinates of the surface and texture binding. Then I render a quad. I've put the color call in my menu inside the glBegin(), defining the color at all 4 vertices. </p> <p>Thanks to my chosen answer: This solved the issue. However, it didn't render the Menu object with the correct color until I returned it to modulate. Not sure, I'll be playing around with it and reading up on this to learn about it. Thank you! </p> <p>[SOVLED] Changes only made to <code>App::OnRender()</code>:</p> <pre><code>glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); MainScreen.RenderQuad(0,0,winWidth,winHeight); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); MainMenu.OnRender(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload