problem with glOrtho

Started by
18 comments, last by Mercury 19 years, 2 months ago
thats the thing tho, i dont want to render a 3d object in ortho projections, i just want to render the UI in ortho and the 3d in non ortho projection.
Advertisement
Quote:Original post by jake_Ghost
thats the thing tho, i dont want to render a 3d object in ortho projections, i just want to render the UI in ortho and the 3d in non ortho projection.


Hmm, could you post your complete rendering code? And to post a screenshot you need to upload it somewhere (any web space will do) and then link to it in your post. A screenshot would be good.
this is my temp rendering stuff cause when i did it with my normal rendering, it was all messed up so i decided just to draw a textured box and see if it does the same thing

#include <windows.h>		// Header File For Windows#include <stdio.h>			// Header File For Standard Input/Output#include <gl\gl.h>			// Header File For The OpenGL32 Library#include <gl\glu.h>			// Header File For The GLu32 Library#include <gl\glaux.h>		// Header File For The Glaux Library#include "DrawScene.h"#include "BMP.h"#include "arb_multisample.h"int GLDraw :: DrawGLScene(GLvoid)									// Here's Where We Do All The Drawing{	this->Reset();	glPushMatrix();		glTranslatef(0,0,zmove);		glEnable(GL_MULTISAMPLE_ARB);		glRotatef(xrot, 1.0f, 0.0f, 0.0f);		glRotatef(yrot, 0.0f, 1.0f, 0.0f);		this->DrawCube( bmp.GetFileName(intTexNum), 0, 0, 0, 1.0f, 1.0f, 1.0f);		glDisable(GL_MULTISAMPLE_ARB);	glPopMatrix();	return TRUE;										// Keep Going}int GLDraw :: DrawUI(GLvoid){	POINT mousePos;		GetCursorPos(&mousePos);	glDisable(GL_DEPTH_TEST);	glMatrixMode(GL_PROJECTION);	glPushMatrix();		glLoadIdentity();		glOrtho( 0, 1024, 768, 0, -1.0f, 1.0f);		glMatrixMode(GL_MODELVIEW);		glPushMatrix();			glLoadIdentity();			this->MapTex("Data/Interface/ui_Bag-4x4.bmp");			glBegin(GL_QUADS);				glTexCoord2f( 0.0f, 1.0f); glVertex3f( mousePos.x, mousePos.y, 0.0);				glTexCoord2f( 0.0f, 0.0f); glVertex3f( mousePos.x, mousePos.y + 256 , 0.0);				glTexCoord2f( 1.0f, 0.0f); glVertex3f( mousePos.x + 256, mousePos.y + 256, 0.0);				glTexCoord2f( 1.0f, 1.0f); glVertex3f( mousePos.x + 256, mousePos.y, 0.0);			glEnd();			glMatrixMode(GL_MODELVIEW);		glPopMatrix();		glMatrixMode(GL_PROJECTION);	glPopMatrix();	glEnable(GL_DEPTH_TEST);	return TRUE;										// Keep Going}int GLDraw :: DrawLoading(GLvoid){	this->Reset();	glDisable(GL_DEPTH_TEST);	glMatrixMode(GL_PROJECTION);	glPushMatrix();		glLoadIdentity();		glOrtho(0,1024,0,768,-1.0f,1.0f);		glMatrixMode( GL_MODELVIEW );		glPushMatrix();			glLoadIdentity();			this->MapTex("Data/Interface/ui_LoadingBar.bmp");			glBegin(GL_QUADS);				glTexCoord2f(0.0f, 1.0f); glVertex3f (256.0,64.0,0.0);				glTexCoord2f(0.0f, 0.0f); glVertex3f (256.0,0.0,0.0);				glTexCoord2f(1.0f, 0.0f); glVertex3f (768.0,0.0,0.0);				glTexCoord2f(1.0f, 1.0f); glVertex3f (768.0,64.0,0.0);			glEnd();			if(LoadAt != 0)			{				this->MapTex("Data/Interface/ui_BarFill.bmp");				// draw main bar				glBegin(GL_QUADS);					glTexCoord2f(0.0f, 1.0f); glVertex3f (286.0,43.0,0.0);					glTexCoord2f(0.0f, 0.0f); glVertex3f (286.0,0.0,0.0);					glTexCoord2f(1.0f, 0.0f); glVertex3f (286 + (int)( (int)(450 / LOADNUM) * LoadAt),0.0,0.0);					glTexCoord2f(1.0f, 1.0f); glVertex3f (286 + (int)( (int)(450 / LOADNUM) * LoadAt),43.0,0.0);				glEnd();			}			glMatrixMode(GL_MODELVIEW);		glPopMatrix();		glMatrixMode(GL_PROJECTION);	glPopMatrix();	glEnable(GL_DEPTH_TEST);	//glDisable(GL_STENCIL_TEST);	return TRUE;										// Keep Going}GLDraw :: DrawCube(std::string TexName, GLfloat x, GLfloat y, GLfloat z, GLfloat height, GLfloat width, GLfloat depth){	this->MapTexType(TexName,FilterType);	glBegin(GL_QUADS);		// Front Face		glTexCoord2f(0.0f, 0.0f); glVertex3f (x-width, y-height, z+depth);		glTexCoord2f(1.0f, 0.0f); glVertex3f (x+width, y-height, z+depth);		glTexCoord2f(1.0f, 1.0f); glVertex3f (x+width, y+height, z+depth);		glTexCoord2f(0.0f, 1.0f); glVertex3f (x-width, y+height, z+depth);		// Back Face		glTexCoord2f(1.0f, 0.0f); glVertex3f (x-width, y-height, z-depth);		glTexCoord2f(1.0f, 1.0f); glVertex3f (x-width, y+height, z-depth);		glTexCoord2f(0.0f, 1.0f); glVertex3f (x+width, y+height, z-depth);		glTexCoord2f(0.0f, 0.0f); glVertex3f (x+width, y-height, z-depth);		// Top Face		glTexCoord2f(0.0f, 1.0f); glVertex3f (x-width, y+height, z-depth);		glTexCoord2f(0.0f, 0.0f); glVertex3f (x-width, y+height, z+depth);		glTexCoord2f(1.0f, 0.0f); glVertex3f (x+width, y+height, z+depth);		glTexCoord2f(1.0f, 1.0f); glVertex3f (x+width, y+height, -1.0f);		// Bottom Face		glTexCoord2f(1.0f, 1.0f); glVertex3f (x-width, y-height, z-depth);		glTexCoord2f(0.0f, 1.0f); glVertex3f (x+width, y-height, z-depth);		glTexCoord2f(0.0f, 0.0f); glVertex3f (x+width, y-height, z+depth);		glTexCoord2f(1.0f, 0.0f); glVertex3f (x-width, y-height, z+depth);		// Right face		glTexCoord2f(1.0f, 0.0f); glVertex3f (x+width, y-height, z-depth);		glTexCoord2f(1.0f, 1.0f); glVertex3f (x+width, y+height, z-depth);		glTexCoord2f(0.0f, 1.0f); glVertex3f (x+width, y+height, z+depth);		glTexCoord2f(0.0f, 0.0f); glVertex3f (x+width, y-height, z+depth);		// Left Face		glTexCoord2f(0.0f, 0.0f); glVertex3f (x-width, y-height, z-depth);		glTexCoord2f(1.0f, 0.0f); glVertex3f (x-width, y-height, z+depth);		glTexCoord2f(1.0f, 1.0f); glVertex3f (x-width, y+height, z+depth);		glTexCoord2f(0.0f, 1.0f); glVertex3f (x-width, y+height, z-depth);	glEnd();}GLDraw :: Reset(){	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	glLoadIdentity();}void GLDraw::MapTex(const std::string &Filename) const{	glBindTexture(GL_TEXTURE_2D, bmp.Texture(Filename));}void GLDraw::MapTexType(const std::string &Filename, const int TYPE) const{	glBindTexture(GL_TEXTURE_2D, bmp.Texture(Filename,TYPE));}


also, when i render everyting w/o the ortho stuff, it looks fine, but as soon as i render the UI it gets messed up.
Hrm, that does all look okay. Any chance you could upload a screenshot somewhere? If you don't have any webspace there are free (I think) image hosting sites around, I can't think of any off the top of my head though.
ok ill go and try and find a place to upload a screenshot
i couldnt find a hosting thing so i used xp's publish to web thing, heres the link

http://ca.msnusers.com/JakeGhost/Documents/untitled.JPG
It gives me an unauthorized access error when I try to go there. It could be my work computer so if you can't upload it somewhere else I'll check again when I get home.
It might not actually effect it, but when in Ortho mode try using glVertex2f(x,y) instead of 3f. This is how my ortho system does it, and it all works great.
alrite thx to all ur help and 1 line more of code the whole messed up thing has been fixed.

every frame i reset the matrix using

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

all i had to do was add this

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

and now it works lol thx for al ur guys help
Quote:Original post by Optus
It might not actually effect it, but when in Ortho mode try using glVertex2f(x,y) instead of 3f. This is how my ortho system does it, and it all works great.

Calling glVertex2f( x, y ) is equivelent to calling glVertex4f( x, y, 0, 1 ), for the record.

This topic is closed to new replies.

Advertisement