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: 18.979 ]
Por: Thiago Henrique Hüpner em 08/05/2015
#include <SDL/SDL.h> #include <SDL/SDL_opengl.h> #include <time.h> #define LARGURA 400 #define ALTURA 400 #define TAMANHO_IMAGEM 128 GLuint carregarImagem(const char *nomeImg) { SDL_Surface *img = SDL_LoadBMP(nomeImg); GLuint textura; if(img == NULL) { printf("Erro ao carregar a imagem %s: %s ",nomeImg,SDL_GetError()); SDL_FreeSurface(img); exit(-1); } glGenTextures(1, &textura); glBindTexture(GL_TEXTURE_2D, textura); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 3, img->w, img->h, 0, GL_RGR, GL_UNSIGNED_BYTE, img->pixels); SDL_FreeSurface(img); return textura; } void colocandoImagemNaTela(GLuint textura, int x,int y) { glBindTexture(GL_TEXTURE_2D, textura); glLoadIdentity(); glTranslatef(x,y,0); glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex2f(0, 0); glTexCoord2f(1, 0); glVertex2f(TAMANHO_IMAGEM, 0); glTexCoord2f(1, 1); glVertex2f(TAMANHO_IMAGEM, TAMANHO_IMAGEM); glTexCoord2f(0, 1); glVertex2f(0, TAMANHO_IMAGEM); glEnd(); } void inicializaOpenGL() { glClearColor(255,255,255,1); glMatrixMode(GL_PROJECTION); glLoadIdentity(); //Necessário para exibir a imagem glEnable(GL_TEXTURE_2D); gluOrtho2D(0,LARGURA,ALTURA,0); glMatrixMode(GL_MODELVIEW); glClear(GL_COLOR_BUFFER_BIT); } void GL_FillRect(SDL_Rect a,int r,int g,int b) { glLoadIdentity(); glColor3ub(r,g,b); glBegin(GL_QUADS); glVertex2f(a.x,a.y); glVertex2f(a.x+a.w,a.y); glVertex2f(a.x+a.w,a.y+a.h); 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; } srand((unsigned)time(NULL)); 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(""Imagenando"",NULL); SDL_Event evento; int estaRodando = 1; inicializaOpenGL(); GLuint textura = carregarImagem("cb.bmp"); while(estaRodando) { while(SDL_PollEvent(&evento)) { switch(evento.type) { case SDL_QUIT: estaRodando = 0; break; default: break; } } glClear(GL_COLOR_BUFFER_BIT); colocandoImagemNaTela(textura,50,50); SDL_Delay(30); SDL_GL_SwapBuffers(); } SDL_Quit(); glDeleteTextures(1, &textura); return 0; }
Ubuntu/Debian/Kali Linux e outros no Android
Criando um sistema operacional com ASM e C++
Apreendendo a utilizar o GNU Debugger (parte 2)
Aprendendo a utilizar o GNU Debugger (parte 1)
Gerencie suas contas financeiras pessoais com Terminal Finances
Como transformar um áudio em vídeo com efeito de forma de onda (wave form)
Como aprovar Pull Requests em seu repositório Github via linha de comando
Como gerar um podcast a partir de um livro em PDF
Organizando seus PDF com o Zotero
Erro no realm join [Resolvido]
Um programa para baixar vídeos: Parabolic
Como Definir o Painel Principal em Múltiplos Monitores no Linux Mint
Sempre que vou baixar algum pacote acontece o erro dpkg (6)
Não consigo montar meu cartão SD (7)
BlueMail não abre no Kubuntu 25.04 (8)
aplicativos criados com webapp-manager não aparecem no menu do xfce (1)