OpenGL and SDL: graphical primitives and images

Hi Everyone,

I have to try plot graphical primitives and images from files in the same window or viewport but appear only graphical primitives or images in this window not both. I dont understand what could be wrong in my code(below):

#include </usr/include/SDL/SDL.h> 
#include </usr/include/GL/gl.h>
#include </usr/include/SDL/SDL_image.h>
#include <stdio.h>
#include <stdlib.h>

    const int SCREEN_WIDTH = 640;
    const int SCREEN_HEIGHT = 480;
    const int SCREEN_BPP = 32;

    int tex;

 
    void init(){
        glClearColor(0.0,0.0,0.0,0.0);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0.0,800,600,1.0,-1.0,1.0);
        glEnable(GL_BLEND);
        glEnable(GL_TEXTURE_2D);
        glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
        
    }
    
    void draw2() {
      
      //init();
      glDisable(GL_TEXTURE_2D); // isto é necessário quando se deseja desenhar SEM texturas
      glColor3f(1,1,0);
      glLineWidth(3);
      glBegin(GL_LINES);
        glVertex2i(0,0);
        glVertex2i(100,100);
      glEnd();
      glColor3f(1,1,1);
    
    
     }
     
     void mostra_imagem() {
     
              SDL_Surface* screen1;
              SDL_Surface* imagemPNG;
              SDL_Rect dest;
              
                            
              
              screen1=SDL_SetVideoMode(800,600,16,SDL_SWSURFACE | SDL_OPENGL);
              
              
              
     
              imagemPNG = IMG_Load("mar.png");
              
              dest.x=10;
              dest.y=10;  
              
              SDL_FillRect(screen1, NULL, 0x3); // Pinta de preto todo o screen
              SDL_BlitSurface(imagemPNG, NULL, screen1, &dest); // mostra imagem do mar
              SDL_UpdateRect(screen1,0,0,0,0); // Atualiza o screen com a imagem blitada
              SDL_Delay(1000);  
        } 
    
    int main(int argc,char** argv){
       
        SDL_Init(SDL_INIT_VIDEO);
        //SDL_Surface* screen=SDL_SetVideoMode(800,600,32,SDL_SWSURFACE|SDL_OPENGL);
        
               
         int running=1;
        Uint32 start;
        SDL_Event event;
        //init();
        mostra_imagem();
        draw2();
        
    
        SDL_Quit();
        return 0;
    }

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.