Archived

This topic is now archived and is closed to further replies.

Can anyone see my Mistake ?

This topic is 5536 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Sorry to post this, as I am trying to avoid asking questions in here, but this one has me stumped. Using MFC and OGL, I am drawing a pair of Lines, and a Bitmap If My window is smaller than my drawing area, then I would expect my lines and Bitmap to not be drawn. i.e. --------------------- | | | | Actual Window | | | | --------------------- | | | | Area where Stuff is Drawn | | --------------------- And when I resize the Window, it will Appear. (I know that I should only draw what is seen, but this is just an experiment.) Using the code below (Texture Loading Code excluded) My Lines are drawn where I would Expect them, but my bitmap appears in the Logical coordinates of the window, not the real coordinates of the world, hence the bitmap is always present. As an aside, I also set the lines colour to be red, but when the window is big enough to see them they are drawn in green (the Bitmap Colour) Code is below, anyone able to explain why this is ? (Again, I know I should only draw what is visible and in view, but I want to understand why this does not work !)
  
/////////////////////////////////////////////////

// Called Whenever a Scene is Drawn

/////////////////////////////////////////////////


void CMapEditorView::DrawScene()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glLoadIdentity();

	glBindTexture(GL_TEXTURE_2D, m_Texture[0]);
	
	glTranslatef(0.0f,0.0f,0.0f);

	glBegin(GL_QUADS);
		glTexCoord2f (0.0f,0.0f);	//B.Right

		glVertex2d(10.0f,10.0f);	
	
		glTexCoord2f (1.0f,0.0f);	//B.Left

		glVertex2d(74.0f,10.0f);	

		glTexCoord2f (1.0f,1.0f);	//T.Right

		glVertex2d(10.0f,74.0f);	

		glTexCoord2f (0.0f,1.0f);	//T.Left

		glVertex2d(74.0f,74.0f);	

	glEnd();

	if (m_blShowGrid)
	{
 
		DrawGrid();
	}
}


void CMapEditorView::DrawGrid()

{

	float x = 64.0f;
	float y = 64.0f;

	glTranslatef(60.0f,60.0f,0.0f);

	
	glColor3f(1.0f,1.0f,1.0f);
	
	glBegin(GL_LINES);
		glVertex2d(0.0f,y/2);
		glVertex2d(x/2,y);
		glVertex2d(x,y/2);
		glVertex2d(x/2,0.0f);
	glEnd();



	}	  
}
  
tia, BP.

Share this post


Link to post
Share on other sites
How do you mean it''s my init code thats not right ?

I know that if I swap the GL_LINES to GL_QUAD in the DrawGrid() function, then I get the same effect i.e. lines always drawn local not global.

I was beginning to think that I was using GL_QUADS wrong. (But I couldn''t see why !)

I have posted my GLInit code in case it helps.


  
/////////////////////////////////////////////////

// OGL Initialisation Function

/////////////////////////////////////////////////


void CMapEditorView::GLInit()
{
glClearColor(0.0,0.0,0.0,0.0);
glEnable(GL_DEPTH_TEST);

if (!LoadGLTextures())
{
bool failed = true;
}
glEnable (GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);


}


Thanks so far,

Bp.

Share this post


Link to post
Share on other sites