Archived

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

meselfs

Lesson 1 in C

Recommended Posts

Hi, I was playing around with NeHe's Lesson 1; I'm a math fanatic and I thought it'd be really fun to write algorithms and test them in a nice, black OpenGL window. I'm also a C fanatic, don't ask why. My app for that stuff is PellesC. So, I try to download the code and load it into PellesC, i thought that for sure I'd get 502938 or so errors, but quite to my surprise I only got about 20 or so. The main problem was that in cpp you use bool, in C you must use BOOL. So, I replaced all bool with BOOL and tried to compile. I now got only two errors: Building main.OBJ. C:\Temp\test\main.c(213): error: Initializer must be constant. C:\Temp\test\main.c(213): error: Too many initializers. *** Error code: 1 *** Done. The code at which this error occors:
static	PIXELFORMATDESCRIPTOR pfd=	// pfd Tells Windows How We Want Things To Be

{
	sizeof(PIXELFORMATDESCRIPTOR),	// Size Of This Pixel Format Descriptor

	1,					// Version Number

	PFD_DRAW_TO_WINDOW |		// Format Must Support Window

	PFD_SUPPORT_OPENGL |		// Format Must Support OpenGL

	PFD_DOUBLEBUFFER,			// Must Support Double Buffering

	PFD_TYPE_RGBA,			// Request An RGBA Format

	bits,					// Select Our Color Depth

	0, 0, 0, 0, 0, 0,				// Color Bits Ignored

	0,					// No Alpha Buffer

	0,					// Shift Bit Ignored

	0,					// No Accumulation Buffer

	0, 0, 0, 0,				// Accumulation Bits Ignored

	16,					// 16Bit Z-Buffer (Depth Buffer)  

	0,					// No Stencil Buffer

	0,					// No Auxiliary Buffer

	PFD_MAIN_PLANE,			// Main Drawing Layer

	0,					// Reserved

	0, 0, 0					// Layer Masks Ignored

};
 
The error occurs at the line that reads bits, // Select Our Color Depth What's wrong? I've tried everythin in my limited knowledge... In case you're all a bunch of pros and thus have no idea where this lesson is, it's here: http://nehe.gamedev.net/lesson.asp?index=01 Thanks in advance [edited by - meselfs on May 26, 2004 9:30:35 PM]

Share this post


Link to post
Share on other sites
I''m pretty crappy when it comes to pure C syntax, but can you declare a static variable in a function and if you can, don''t you have to initialize it the first thing you do before running any other code?
It was a VERY long time since I even tried correcting C code, but if my memorie doesn''t fail me I had to decalre everything in the top of the function.
Good luck,

- Patrik Willbo

The Lord says He can get me out of this mess, but He''s pretty sure you''re fucked.
- Stephen (Braveheart)

Share this post


Link to post
Share on other sites
''lo,

I also use PellesC. You can''t declare and initialise a structure with a variable.
You must do something like this : (i use nehe basecode)


PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be
{
sizeof (PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
1, // Version Number
PFD_DRAW_TO_WINDOW | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
//window->init.bitsPerPixel, // Select Our Color Depth
32,
0, 0, 0, 0, 0, 0, // Color Bits Ignored
0, // No Alpha Buffer
0, // Shift Bit Ignored
0, // No Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits Ignored
16, // 16Bit Z-Buffer (Depth Buffer)
0, // No Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks Ignored
};
RECT windowRect = {0, 0, 0, 0}; // Define Our Window Coordinates
GLuint PixelFormat;

//You put the variable you want in the pfd.
pfd.cColorBits=window->init.bitsPerPixel;

Share this post


Link to post
Share on other sites
Thanks Bourricot, but it didn''t fully solve:

First, it didn''t like GLuint PixelFormat;, it turned out that this was defined elsewhere, so I removed it and all was well, except for the following bit of code:

pfd.cColorBits=window->init.bitsPerPixel;

It gives the following errors:

C:\Temp\Line\line.c(226): error: Undeclared identifier ''window''.
C:\Temp\Line\line.c(226): error: Left operand of -> has incompatible type ''int''.
C:\Temp\Line\line.c(226): error: Left operand of . has incompatible type ''int''.

I killed the first error with:

int window;

But the other two don''t give up.

Share this post


Link to post
Share on other sites
Oups, sorry it was a cut and paste from nehe base code.

for lesson 1
pfd.cColorBits=bits;


static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be

{
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor

1, // Version Number

PFD_DRAW_TO_WINDOW | // Format Must Support Window

PFD_SUPPORT_OPENGL | // Format Must Support OpenGL

PFD_DOUBLEBUFFER, // Must Support Double Buffering

PFD_TYPE_RGBA, // Request An RGBA Format

0, // Select Our Color Depth

0, 0, 0, 0, 0, 0, // Color Bits Ignored

0, // No Alpha Buffer

0, // Shift Bit Ignored

0, // No Accumulation Buffer

0, 0, 0, 0, // Accumulation Bits Ignored

16, // 16Bit Z-Buffer (Depth Buffer)

0, // No Stencil Buffer

0, // No Auxiliary Buffer

PFD_MAIN_PLANE, // Main Drawing Layer

0, // Reserved

0, 0, 0 // Layer Masks Ignored

};
pfd.cColorBits = bits;


Anyway, you should use the lcc win32 port. pellesC is derived from LCC.

Share this post


Link to post
Share on other sites