Sign in to follow this  
falledAngel

glOrtho problems.....

Recommended Posts

falledAngel    122
Hi people, I need to build a 2D application, and I've choose glOrtho perspective, but when I'm trying to put some color on the view all becomes black, any suggestion? P.D: I found some code that let me put some text on the view, with GLPrint and Buildfont but I can't see nothing. Thank you, ans sorry for my bas writing! visca el BARÇA!!!!

Share this post


Link to post
Share on other sites
CRACK123    235
It would be good to see some code into what you are doing, it probably could be that you are not clearning the buffer or drawing nothing. Various things could be wrong.

On the other hand you could also take Nehe Lesson 1 and change the gluPerspective to glOrtho and make modifications to it.


Share this post


Link to post
Share on other sites
Fella    102
If you want only 2D try to set up the orthographic projection with:
gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top)
As you can see this function has no depth parameter as glOrtho() has.

If you can use GLUT try using this function for text output.


void outputText(int x, int y, char *string)
{
int len, i;
glRasterPos2f(x, y);
len = (int) strlen(string);
for (i = 0; i < len; i++)
{
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, string[i]);
}
};

Share this post


Link to post
Share on other sites
Fella    102
Quote:
i've choose glOrtho perspective


I think saying "glOrtho perspective" is an oxymoron. There are two types of projections: orthographic and perspective. With orthographic projection objects appear same size if same dimension regardless of depth while with perspective projection objects placed further in depth appear smaller than the nearer objects. I think it is not correct to say "glOrtho perspective" since this function sets up orthographic projection not the perspective one. Please correct me if I am wrong since I am not absolutely sure about this terminology.

Share this post


Link to post
Share on other sites
falledAngel    122
Thank you so much to answer me.

I've solved the problem I had when all becames black
I choose glColor4i and if I use glColor3f doesn't became black,
but now, the problem is that the color is applied as a tint on all objects on the scene. What's the problem?

the code:
...
GLvoid ReSizeGLScene(GLsizei width, GLsizei height) { Initialize The GL Window
if (height==0) { height=1;
}
glViewport(0,0,width,height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1.0, 1.0, -1.0, 1.0, 1, 5);
glMatrixMode(GL_MODELVIEW); ///!!!!This can be a possible error glLoadIdentity(); ///!!!!Maybe change to another MODe????
}
...
int DrawGLScene(GLvoid) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindTexture(GL_TEXTURE_2D, textura[0]);
glLoadIdentity(); // Reset The View
glTranslatef(0.0f,0.0f,-5.0f); // Move Left And Into The Screen
if (bMouseEsq) {
setColor(1,1,1,1);
}
glBegin(GL_QUADS);
//!!Don't worry about this part, m is menu,with x pos, y pos, width an height, setGLcoord convert the "coords" in pixels.
glTexCoord2f(0.0f, 1.0f);
point p;
p=setGLCoord(m.getXPos(),m.getYPos());
glVertex2f(p.x, p.y);
glTexCoord2f(0.0f, 0.0f);
p=setGLCoord(m.getXPos(),m.getYPos() + m.getHeight());
glVertex2f(p.x, p.y);
glTexCoord2f(1.0f, 0.0f);
p=setGLCoord(m.getXPos() + m.getWidth(),m.getYPos() + m.getHeight());
glVertex2f(p.x, p.y);
glTexCoord2f(1.0f, 1.0f);
p=setGLCoord(m.getXPos() + m.getWidth(),m.getYPos());
glVertex2f(p.x, p.y);
glEnd()...


What can I do???

Share this post


Link to post
Share on other sites
falledAngel    122
...
glBegin(GL_QUADS);
glColor3f(0.5f,0.5f,1.0f);
p=setGLCoord(10,10);
glVertex2f(p.x, p.y);
p=setGLCoord(10,200);
glVertex2f(p.x, p.y);
p=setGLCoord(20,200);
glVertex2f(p.x, p.y);
p=setGLCoord(20,10);
glVertex2f(p.x, p.y);
glEnd();

}

Share this post


Link to post
Share on other sites
CRACK123    235
glColor4* is RGBA meaning implies if alpha is max then it becomes transparent I think(not sure exactly how to describe it of my explanation is correct). So you would have to choose correct value of alpha in that case. But if you don't want alpha then just stick to glColor3*.

Coming to restricting the tint with the texture you would have to use GL_REPLACE as one of the texture environment (using glTexEnv*) while binding the texture to the polygon for it to ignore the color.

Hope this helps.


Share this post


Link to post
Share on other sites
falledAngel    122
Sorry I don't know how apply glTextEnv, but a very stange think is happening now.

glBegin(GL_QUADS);
glColor3f(222,231,0);
p=setGLCoord(10,10);
glVertex2f(p.x, p.y);
p=setGLCoord(10,200);
glVertex2f(p.x, p.y);
p=setGLCoord(20,200);
glVertex2f(p.x, p.y);
p=setGLCoord(20,10);
glVertex2f(p.x, p.y);
glEnd();

glBegin(GL_QUADS);
glColor3f(22,2,233);
p=setGLCoord(70,10);
glVertex2f(p.x, p.y);
p=setGLCoord(70,200);
glVertex2f(p.x, p.y);
p=setGLCoord(121,200);
glVertex2f(p.x, p.y);
p=setGLCoord(220,10);
glVertex2f(p.x, p.y);
glEnd();

The first picture I see it in yellow tint color, but the second one, erases the tint, on the second object, and in the menu posted before. Can be the mode of the projection Matrix??????

Share this post


Link to post
Share on other sites
falledAngel    122
I'm lost. Maybe it's the way I declare de Texture?????

H-E-L-P

int LoadGLTextures() {
int Status = FALSE;
AUX_RGBImageRec *TextureImage[1];
memset(TextureImage, 0, sizeof(void *)*1);
if (TextureImage[0]=LoadBMP("Imatges/untitled2.bmp")) {
Status = TRUE;
glGenTextures(1, &textura[0]);
glBindTexture(GL_TEXTURE_2D, textura[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

}
if (TextureImage[0]) {
if (TextureImage[0]->data) {
free(TextureImage[0]->data);
}
}
return Status;
}

int InitGL(GLvoid) {
nFitxer = "Imatges/untitled2.bmp";
m.setXPos(160);
m.setYPos(360);
m.setWidth(300);
m.setHeight(50);
m.setFitxer(nFitxer);

if (!LoadGLTextures()) {
return FALSE;
}
glEnable(GL_TEXTURE_2D);
glClearColor(0.3f, 0.3f, 0.3f, 0.5f);
glClearDepth(1.0f); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_BLEND);
BuildFont();
return TRUE;
}

Share this post


Link to post
Share on other sites
Gorax    202
Quote:
Original post by CRACK123
glColor4* is RGBA meaning implies if alpha is max then it becomes transparent I think(not sure exactly how to describe it of my explanation is correct).


Actually, when the alpha value increases, things become more opaque, unless you play with the blending operations, in which case it can be changed.

Anyway, going over your code fairly quickly, I've noticed the colours you're using in the functions are completely inappropriate (I've done it before, so don't feel too bad about it). What you need to do is ensure that all of your colours are in the ranges 0.0f to 1.0f when using the float/double functions, otherwise you're going to end up with a lot of problems.

Also, the internal format you're using for the images shouldn't include numbers (your '3' for example), but should include the defined types found in the OpenGL header (GL_RGB, GL_RGBA, etc.).

Finally, I see you've enabled blending, but you haven't specified the blending function you want to use. The one most people tend to go with is glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA), since that does all of the alpha blending fairly well. Also, you might want to enable alpha testing (glEnable(GL_ALPHA_TEST)), and set some cut-off value so things don't look dodgy when the alpha values get too low (glAlphaFunc(GL_GREATER,0.2f)).

Let us know if this helps, or if it fixes the problem, or if it still persists (in which case I'm sure somebody (if not myself) will be around to help you through it).

Share this post


Link to post
Share on other sites
falledAngel    122
Well, let me thank you first all the help I'm recieving and let me apologize for my bad writting.

I have applied all the things you said to me, but, the only thing that have succeeded has been changing the int to floats in the glColor*.

The other things seems to not change the results on my application.

Now I have changed the order of drawing my objects in the screen.

I have three squares and a menu, that's a textured square and it's the last object to draw. By using glColor3f I change the color of the objects but I don't wanna use a color for the menu because it have his own texture. the problem is that the color applied to the last object is applied to the menu.

Can I put some command to avoid this????

P.D: I think that putting this objects in a stack should be better, in order to click and drag some object, to create some kind of depth. Well, in order to do this maybe it should be better a vector. Ordering a stack it would be a hard job!

Share this post


Link to post
Share on other sites
CRACK123    235
Quote:
Original post by Gorax

Actually, when the alpha value increases, things become more opaque, unless you play with the blending operations, in which case it can be changed.



As I thought I was getting mixed up :). Thanks for correcting

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this