Tutorial OpenGL v2.0
Finalmente chegou! Após quase 1 ano depois de meu primeiro artigo sobre OpenGL, chegou a versão 2.0. Clique e fique mais Geek.
[ Hits: 20.482 ]
Por: Thiago Henrique Hüpner em 08/05/2015
#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>
#define LARGURA 400
#define ALTURA 400
void inicializaOpenGL(){
glClearColor(255,255,255,1);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,LARGURA,ALTURA,0);
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT);
}
// Simulando o SDL_FillRect
void GL_FillRect(SDL_Rect a,int r,int g,int b){
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glColor3ub(r,g,b);
glBegin(GL_QUADS);
// Lado Superior Esquerdo
glVertex2f(a.x,a.y);
// Lado Superior Direito
glVertex2f(a.x+a.w,a.y);
// Lado Inferior Direito
glVertex2f(a.x+a.w,a.y+a.h);
// Lado Inferior Esquerdo
glVertex2f(a.x,a.y+a.h);
glEnd();
}
int main(int argc,char *argv[]){
if(SDL_Init(SDL_INIT_VIDEO) < 0){
printf("Erro : %s
",SDL_GetError());
return -1;
}
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 2 );
SDL_Surface * tela = SDL_SetVideoMode(LARGURA,ALTURA,32,SDL_OPENGL);
if(tela == NULL){
printf("Erro : %s
",SDL_GetError());
SDL_Quit();
return -1;
}
SDL_WM_SetCaption("Tudo Junto e Misturado",NULL);
SDL_Event evento;
int estaRodando = 1;
SDL_Rect retangulo;
inicializaOpenGL();
while(estaRodando){
while(SDL_PollEvent(&evento)){
switch(evento.type){
case SDL_QUIT:
estaRodando = 0;
break;
default:
break;
}
}
// Propriedades do Retangulo
// Posição X
retangulo.x = 10;
// Posição Y
retangulo.y = 10;
// Aqui a coisa começa a ficar interessante ...
// Podemos alterar a Largura do Retangulo e ...
retangulo.w = 50;
// ... a Altura do Retangulo
retangulo.h = 50;
GL_FillRect(retangulo,255,0,0);
SDL_Delay(30);
SDL_GL_SwapBuffers();
}
SDL_Quit();
return 0;
}

Ubuntu/Debian/Kali Linux e outros no Android
Como aprender a programar e produzir aplicativos usando Euphoria
Reprodução de arquivos WAV com SDL_mixer e linguagem C
XFCE - quase um Gnome ou Plasma mas muito mais leve
LXQT - funcional para máquinas pererecas e usuários menos exigentes
Instalação do K3s Single-Node com Rancher no Ubuntu 24.04
Usei o NotebookLM para Auditar Logs do Linux
Cinnamon seria a aposta acertada frente às outras interfaces gráficas mais populares?
[Resolvido] Sumiço de redes e micro quedas no iwd/iwgtk (Realtek rtw88)
Como Configurar DNS Reverso (PTR) em Ambientes Linux e Microsoft
Preparando o Ambiente para Administrar o Samba 4 a partir do Windows com RSAT
WiFi Seguro: EAP-TLS com FreeRADIUS e Active Directory (LDAP)
A diferença entre a fala de um Samuel e a fala de alguém que conhece o... (4)









