SM Posted February 23, 2013 at 04:19 PM Report #496747 Posted February 23, 2013 at 04:19 PM (edited) Boas, como se redimensiona uma janela em openGL de forma a nunca deformar o seu conteudo ? deixo aqui a função que tinha pra reshape : void myReshape(GLsizei w, GLsizei h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-2.0f, 2.0f, -2.0f, 2.0f, -2.0f, 2.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } Edited February 23, 2013 at 05:02 PM by thoga31 Colocado GeSHi + removidas maiúsculas do título
HappyHippyHippo Posted February 23, 2013 at 04:59 PM Report #496752 Posted February 23, 2013 at 04:59 PM (edited) - saber o rácio largura altura - converter os dados conforme esse racio void myReshape(GLsizei w, GLsizei h) { double ratio = 0.0; glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (w > h) { ratio = w / h; glOrtho(-2.0f * ratio, 2.0f * ratio, -2.0f, 2.0f, -2.0f, 2.0f); } else { ratio = h / w; glOrtho(-2.0f, 2.0f, -2.0f * ratio, 2.0f * ratio, -2.0f, 2.0f); } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } ps : não testado Edited February 23, 2013 at 04:59 PM by HappyHippyHippo IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
SM Posted February 23, 2013 at 07:13 PM Author Report #496764 Posted February 23, 2013 at 07:13 PM Eu ja tinha testado assim e não deu :x
HappyHippyHippo Posted February 23, 2013 at 09:47 PM Report #496787 Posted February 23, 2013 at 09:47 PM foi confirmar (não testei, vi na net) é parece que eu estava correcto ... se continuas com problemas então não será no código apresentado e terás de dar um exemplo do que está a acontecer (e provavelmente mais código relacionado com o problema) IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
SM Posted February 24, 2013 at 12:18 PM Author Report #496830 Posted February 24, 2013 at 12:18 PM (edited) Com esse código sempre que tento mudar o tamanho da janela , ela desaparece.. O que posso fazer para isso nao acontecer? E quando recupero a execução a janela já esta maior e a imagem do viewport toda deformada. Edited February 24, 2013 at 12:20 PM by SM
HappyHippyHippo Posted February 24, 2013 at 02:15 PM Report #496844 Posted February 24, 2013 at 02:15 PM apresenta todo o código que tens IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
SM Posted February 24, 2013 at 11:43 PM Author Report #496902 Posted February 24, 2013 at 11:43 PM #include "main.h" #include <GLUT/glut.h> void myReshape(GLsizei w, GLsizei h) { double ratio = 0.0; glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (w > h) { ratio = w / h; glOrtho(-2.0f * ratio, 2.0f * ratio, -2.0f, 2.0f, -2.0f, 2.0f); } else { ratio = h / w; glOrtho(-2.0f, 2.0f, -2.0f * ratio, 2.0f * ratio, -2.0f, 2.0f); } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void myDisplay(void) { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.0f, 1.0f, 0.0f); glBegin(GL_POLYGON); glVertex3f(-1.0f, -1.0f, 0.0f); glVertex3f(0.0f, -1.0f, 0.0f); glVertex3f(0.0f, 1.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 0.0f); glEnd(); glColor3f(1.0f, 0.0f, 0.0f); glBegin(GL_POLYGON); glVertex3f(1.0f, 1.0f, 0.0f); glVertex3f(1.0f, -1.0f, 0.0f); glVertex3f(0.0f, -1.0f, 0.0f); glVertex3f(0.0f, 1.0f, 0.0f); glEnd(); glFlush(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize (400, 400); glutInitWindowPosition (-1, -1); glutCreateWindow(" Teste"); glutDisplayFunc(myDisplay); glutReshapeFunc(myReshape); glutMainLoop(); }
HappyHippyHippo Posted February 25, 2013 at 11:16 AM Report #496935 Posted February 25, 2013 at 11:16 AM void myReshape(GLsizei w, GLsizei h) { double ratio = (GLdouble)w / (GLdouble)h; glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (ratio >= 1.0) { glOrtho(-2.0f * ratio, 2.0f * ratio, -2.0f, 2.0f, -2.0f, 2.0f); } else { glOrtho(-2.0f, 2.0f, -2.0f * (1.0 / ratio), 2.0f * (1.0 / ratio), -2.0f, 2.0f); } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
SM Posted February 25, 2013 at 07:49 PM Author Report #496977 Posted February 25, 2013 at 07:49 PM Humm, então o problema era por o w e o h não estarem convertidos em GLdouble? Muito obrigado 🙂
HappyHippyHippo Posted February 25, 2013 at 07:50 PM Report #496978 Posted February 25, 2013 at 07:50 PM sim, isto porque resultaria numa divisão inteira, o que não é o pretendido IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now