• Advertisement
Sign in to follow this  

Problems compiling

This topic is 4252 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

I recently have found the cone3d tutorials page and started working my way through them. I know the basics of c++ and I felt that I would move to the next step and start learning about graphics. I followed my way through lesson 01 and tried compiling it when I was finished. I fixed the compile errors that I knew how too but there are still several more that I was unsuccessful at fixing. Any help is greatly appreciated.
#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>

void Slock(SDL_Surface *screen)
{
	if ( SDL_MUSTLOCK(screen) )
	{
		if ( SDL_LockSurface(screen) < 0 )
		{
			return;
		}
	}
}

void Sulock(SDL_Surface *screen)
{
	if (SDL_MUSTLOCK(screen) )
	{
		SDL_UnlockSurface(screen);
	}
}

void DrawPixel(SDL_Surface *screen, int x, int y, Uint8 R, Unit8 G, Uint8 B)
{
	Uint32 color = SDL_MapRGB(screen->format, R, G, B);
	switch (screen->format->BytesPerPixel)
	{
	case 1: // Assuming 8-bpp
		{
			Uint8 *bufp;
			bufp = (Uint8 *)screen->pixels + y*screen->pitch + x;
			*bufp = color;
		}
		break;
	case 2:	// Probably 15-bpp ot 16-bpp
		{
			Unit16 *bufp;
			bufp = (Uint16 *)screen->pixels + y*screen->pitch/2 + x;
			*bufp = color;
		}
		break;
	case 3:	// Slow 24-bpp mode, usually not used
		{
			Uint8 *bufp;
			bufp = (Uint16 *)screen->pixels + y*screen->pitch + x * 3;
			if(SDL_BYTEORDER == SDL_LIL_ENDIAN)
			{
				bufp[0] = color;
				bufp[1] = color >> 8;
				bufp[2] = color >> 16;
			}
			else
			{
				bufp[2] = color;
				bufp[1] = color >> 8;
				bufp[0] = color >> 16;
			}
		}
		break;
	case 4:	// Probably 32-bpp
		{
			Uint32 *bufp;
			bufp = (Uint32 *)screen->pixels + y*screen->pitch/4 + x;
			*bufp = color;
		}
 		break;
	}
}

void DrawScene(SDL_Surface *screen)
{
	Slock(screen);
	for(int x=0;x<640;x++)
	{
		for(int y=0;y<480;y++)
		{
			DrawPixel(screen, x, y, y/2, y/2, x/3);
		}
	}
	SuLock(screen);
	SDL_Flip(screen);
}

int main()
{
	if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 )
	{
		printf("Unable to initialize SDL: %s\n", SDL_GetError());
		exit(1);
	}
	atexit(SDL_Quit);

	SDL_Surface *screen;
	screen = SDL_SetVideoMode(640, 480, 0, SDL_HWSURFACE|SDL_DOUBLEBUF);
	if ( screen == NULL )
	{
		printf("Unable to set resolution 640X480: %s\n", SDL_GetError());
		exit(1);
	}
	int done = 0;

	while (done == 0)
	{
		SDL_Event event;
		
		while ( SDL_PollEvent(&event) )
		{
			if (event.type == SDL_QUIT)
			{
				done = 1;
			}
			if (event.type == SDL_KEYDOWN )
			{
				if ( event.key.keysym.sym == SDLK_ESCAPE)
				{
					done = 1;
				}
			}
		}

		DrawScene(screen);
	}
	
		return 0;
}

And these are the errors:
Compiling...
Lesson01.cpp
C:\Documents and Settings\Faded Maximus\Desktop\MyProjects\Lesson01\Lesson01.cpp(31) : error C2061: syntax error : identifier 'Unit8'
C:\Documents and Settings\Faded Maximus\Desktop\MyProjects\Lesson01\Lesson01.cpp(33) : error C2065: 'G' : undeclared identifier
C:\Documents and Settings\Faded Maximus\Desktop\MyProjects\Lesson01\Lesson01.cpp(33) : error C2065: 'B' : undeclared identifier
C:\Documents and Settings\Faded Maximus\Desktop\MyProjects\Lesson01\Lesson01.cpp(45) : error C2065: 'Unit16' : undeclared identifier
C:\Documents and Settings\Faded Maximus\Desktop\MyProjects\Lesson01\Lesson01.cpp(45) : error C2065: 'bufp' : undeclared identifier
C:\Documents and Settings\Faded Maximus\Desktop\MyProjects\Lesson01\Lesson01.cpp(45) : warning C4552: '*' : operator has no effect; expected operator with side-effect
C:\Documents and Settings\Faded Maximus\Desktop\MyProjects\Lesson01\Lesson01.cpp(46) : error C2440: '=' : cannot convert from 'unsigned short *' to 'int'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Documents and Settings\Faded Maximus\Desktop\MyProjects\Lesson01\Lesson01.cpp(47) : error C2100: illegal indirection
C:\Documents and Settings\Faded Maximus\Desktop\MyProjects\Lesson01\Lesson01.cpp(53) : error C2440: '=' : cannot convert from 'unsigned short *' to 'unsigned char *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\Documents and Settings\Faded Maximus\Desktop\MyProjects\Lesson01\Lesson01.cpp(85) : error C2660: 'DrawPixel' : function does not take 6 parameters
C:\Documents and Settings\Faded Maximus\Desktop\MyProjects\Lesson01\Lesson01.cpp(88) : error C2065: 'SuLock' : undeclared identifier
Error executing cl.exe.

Lesson01.obj - 10 error(s), 1 warning(s)

Share this post


Link to post
Share on other sites
Advertisement
The errors indicate that you've typed 'Unit' rather than 'Uint' in a couple of places.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Silly me, I was overlooking that and just assumed they all read Uint. Thanks for the help, I have it down to two errors now.


Compiling...
Lesson01.cpp
C:\Documents and Settings\Faded Maximus\Desktop\MyProjects\Lesson01\Lesson01.cpp(53) : error C2440: '=' : cannot convert from 'unsigned short *' to 'unsigned char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\Documents and Settings\Faded Maximus\Desktop\MyProjects\Lesson01\Lesson01.cpp(88) : error C2065: 'SuLock' : undeclared identifier
Error executing cl.exe.

Lesson01.exe - 2 error(s), 0 warning(s)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement