Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming

Reply
 
LinkBack Thread Tools
Old 01-03-09   #1 (permalink)
New to Overclock.net
 
intel nvidia

Join Date: Nov 2007
Location: Surrey, BC, Canada
Posts: 269

Rep: 14 serge2k Unknown
Unique Rep: 14
Trader Rating: 1
Default problem with openGL (c++)

I'm trying to learn openGL and it's been going pretty well. I'm just following the code from a book and modifying it suit my application.

I'm finally at the point where I can try my first polygon. Everything seems right and it all compiles correctly.

The problem is that my window clears to white (which is correct) but nothing shows up.

here is the code for the rendering function
Code:
void Render()
{
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glClearColor (1.0f, 1.0f, 1.0f, 1.0f);
	glLoadIdentity();
	glPushMatrix();
	glTranslatef (0.0f, 0.0f, 0.0f);
	glBegin (GL_TRIANGLES);
		glVertex3f (0.0f, 0.0f, 10.0f);
		glVertex3f (0.0f, 1.0f, 10.0f);
		glVertex3f (1.0f, 1.0f, 10.0f);
	glEnd();
	glPopMatrix();
	SwapBuffers (g_Graphics.hDC);
}
I can post the rest of my code if the problem isn't obvious from that.
__________________
System: The Black Box
CPU
E6750
Motherboard
Asus P5N-E SLI
Memory
2GB DDR-2 800 MHz
Graphics Card
EVGA 8800 GTS 640
Hard Drive
2x250GB Seagate in Raid 0, 2x1TB WD Caviar Blacks
Sound Card
integrated
Power Supply
Antec Earthwatts 500W
Case
Antec Sonata 3
CPU cooling
Xigmatek HDT S1283
GPU cooling
stock
OS
Windows 7 Ultimate x64
Monitor
22" LG
serge2k is offline   Reply With Quote
Old 01-03-09   #2 (permalink)
With great difficulty
 
rabidgnome229's Avatar
 
intel nvidia

Join Date: Feb 2006
Location: Pittsburgh
Posts: 5,210

Rep: 614 rabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famous
Unique Rep: 370
FAQs Submitted: 6
Trader Rating: 5
Default

Quote:
Originally Posted by serge2k View Post
I'm trying to learn openGL and it's been going pretty well. I'm just following the code from a book and modifying it suit my application.

I'm finally at the point where I can try my first polygon. Everything seems right and it all compiles correctly.

The problem is that my window clears to white (which is correct) but nothing shows up.

here is the code for the rendering function
Code:
void Render()
{
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glClearColor (1.0f, 1.0f, 1.0f, 1.0f);
	glLoadIdentity();
	glPushMatrix();
	glTranslatef (0.0f, 0.0f, 0.0f);
	glBegin (GL_TRIANGLES);
		glVertex3f (0.0f, 0.0f, 10.0f);
		glVertex3f (0.0f, 1.0f, 10.0f);
		glVertex3f (1.0f, 1.0f, 10.0f);
	glEnd();
	glPopMatrix();
	SwapBuffers (g_Graphics.hDC);
}
I can post the rest of my code if the problem isn't obvious from that.
There are several things wrong/weird with that snippet. The show stopper is that the triangle is behind the camera. The default for OpenGL is a camera located at (0, 0, 0) looking in the direction (0, 0, -1) - i.e. located at the origin looking down the negative z axis. Your triangle is at z= +10, which is behind that camera.

A few other notes (not as important). glClearColor shouldn't be called every time that Render is called, especially if it doesn't change, and it definitely should not be called after calling glClear. One call in your init function sets it until it changes (seems to be never in your case). Also, your glTranslate call doesn't do anything because it translates by 0 units in each direction. The last thing I'd mention is that it doesn't make much sense to push and pop the matrix if you aren't performing any transformations, and especially since you just set it to the identity every time Render is called anyway. You're saving the identity matrix, doing nothing to it, restoring it, then overwriting it with itself on the next pass.
__________________
System: It goes to eleven
CPU
E6300
Motherboard
DS3
Memory
2GB XMS2 DDR2-800
Graphics Card
EVGA 8600GTS
Hard Drive
1.294 TB
Sound Card
Audigy 2 ZS
Power Supply
Corsair 520HX
Case
Lian-Li v1000B Plus
CPU cooling
TTBT
GPU cooling
Thermalright V2
OS
Arch Linux/XP
Monitor
Samsung 226bw
rabidgnome229 is offline Overclocked Account   Reply With Quote
Old 01-04-09   #3 (permalink)
New to Overclock.net
 
intel nvidia

Join Date: Nov 2007
Location: Surrey, BC, Canada
Posts: 269

Rep: 14 serge2k Unknown
Unique Rep: 14
Trader Rating: 1
Default

I moved the GLClearColor into my init function and removed the translate and matrix stuff

Code:
void Render()
{
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	
	glLoadIdentity();
	glBegin (GL_TRIANGLES);
		glVertex3f (0.0f, 0.0f, -1.0f);
		glVertex3f (0.0f, 1.0f, -1.0f);
		glVertex3f (1.0f, 1.0f, -1.0f);
	glEnd();
	SwapBuffers (g_Graphics.hDC);
}
still nothing
__________________
System: The Black Box
CPU
E6750
Motherboard
Asus P5N-E SLI
Memory
2GB DDR-2 800 MHz
Graphics Card
EVGA 8800 GTS 640
Hard Drive
2x250GB Seagate in Raid 0, 2x1TB WD Caviar Blacks
Sound Card
integrated
Power Supply
Antec Earthwatts 500W
Case
Antec Sonata 3
CPU cooling
Xigmatek HDT S1283
GPU cooling
stock
OS
Windows 7 Ultimate x64
Monitor
22" LG
serge2k is offline   Reply With Quote
Old 01-04-09   #4 (permalink)
With great difficulty
 
rabidgnome229's Avatar
 
intel nvidia

Join Date: Feb 2006
Location: Pittsburgh
Posts: 5,210

Rep: 614 rabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famous
Unique Rep: 370
FAQs Submitted: 6
Trader Rating: 5
Default

You never set the drawing color with glColor. It's probably defaulting to whatever the clear color is
__________________
System: It goes to eleven
CPU
E6300
Motherboard
DS3
Memory
2GB XMS2 DDR2-800
Graphics Card
EVGA 8600GTS
Hard Drive
1.294 TB
Sound Card
Audigy 2 ZS
Power Supply
Corsair 520HX
Case
Lian-Li v1000B Plus
CPU cooling
TTBT
GPU cooling
Thermalright V2
OS
Arch Linux/XP
Monitor
Samsung 226bw
rabidgnome229 is offline Overclocked Account   Reply With Quote
Reply

Tags
c++, graphics, opengl


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -5. The time now is 07:25 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2009 Shogun Interactive Development. Most rights reserved.
Page generated in 0.14226 seconds with 8 queries