Thread: Error I have in OpenGL tutorial on this site.

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    2

    Error I have in OpenGL tutorial on this site.

    Hey, I just started to learn C++ today, but being as I am experienced in other languages like PHP, I have grasped most of the concepts quite firmly. However, when I wanted to start learned OpenGL and integrating some images/graphics into my scripts etc. I found this tutorial HERE quite handy. However, this line of code seen below gives me some problems that I am unsure of:
    Code:
    /*	Trim fat from windows*/
    #define WIN32_LEAN_AND_MEAN	
    #pragma comment(linker, "/subsystem:windows")
    /*	Pre-processor directives*/
    #include "stdafx.h"
    #include <windows.h>
    /*	Windows Procedure Event Handler*/
    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	PAINTSTRUCT paintStruct;
    	/*	Device Context*/
    	HDC hDC; 
    	/*	Text for display*/
    	char string[] = "Hello, World!"; 
    	/*	Switch message, condition that is met will execute*/
    	switch(message)
    	{
    		/*	Window is being created*/
    		case WM_CREATE: 
    			return 0;
    			break;
    		/*	Window is closing*/
    		case WM_CLOSE: 
    			PostQuitMessage(0);
    			return 0;
    			break;
    		/*	Window needs update*/
    		case WM_PAINT: 
    			hDC = BeginPaint(hwnd,&paintStruct);
    			/*	Set txt color to blue*/
    			SetTextColor(hDC, COLORREF(0x00FF0000));
    			/*	Display text in middle of window*/
    			TextOut(hDC,150,150,string,sizeof(string)-1);
    			EndPaint(hwnd, &paintStruct);
    			return 0;
    			break;
    		default:
    			break;
    	}
    	return (DefWindowProc(hwnd,message,wParam,lParam));
    }
    /*	Main function*/
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
    	WNDCLASSEX  windowClass;		//window class
    	HWND		hwnd;				//window handle
    	MSG			msg;				//message
    	bool		done;				//flag saying when app is complete
    	/*	Fill out the window class structure*/
    	windowClass.cbSize = sizeof(WNDCLASSEX);
    	windowClass.style = CS_HREDRAW | CS_VREDRAW;
    	windowClass.lpfnWndProc = WndProc;
    	windowClass.cbClsExtra = 0;
    	windowClass.cbWndExtra = 0;
    	windowClass.hInstance = hInstance;
    	windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    	windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
    	windowClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    	windowClass.lpszMenuName = NULL;
    	windowClass.lpszClassName = "MyClass";
    	windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
    	/*	Register window class*/
    	if (!RegisterClassEx(&windowClass))
    	{
    		return 0;
    	}
    	/*	Class registerd, so now create window*/
    	hwnd = CreateWindowEx(NULL,		//extended style
    		"MyClass",			//class name
    		"A Real Win App",		//app name
    		WS_OVERLAPPEDWINDOW |		//window style
    		WS_VISIBLE |
    		WS_SYSMENU,
    		100,100,			//x/y coords
    		400,400,			//width,height
    		NULL,				//handle to parent
    		NULL,				//handle to menu
    		hInstance,			//application instance
    		NULL);				//no extra parameter's
    	/*	Check if window creation failed*/
    	if (!hwnd)
    		return 0;
    	done = false; //initialize loop condition variable
    	/*	main message loop*/
    	while(!done)
    	{
    		PeekMessage(&msg,hwnd,NULL,NULL,PM_REMOVE);
    		if (msg.message == WM_QUIT) //check for a quit message
    		{
    			done = true; //if found, quit app
    		}
    		else
    		{
    			/*	Translate and dispatch to event queue*/
    			TranslateMessage(&msg); 
    			DispatchMessage(&msg);
    		}
    	}
    	return msg.wParam;
    }
    This returns some errors in my compiler.

    The first one:
    \Dev-Cpp\my programs\1\Untitled1.cpp C:\Dev-Cpp\my programs\1\C stdafx.h: No such file or directory.
    Why is there saying there is no such file or directory? I am using BloodShed Dev-C++ for my compiler and I tried downloading an openglut package from their update page. What do I need to install or get to make this code and tutorial work for me? Thanks again for your help!

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Visual C++ uses something called precompiled headers. It basically means you put commonly used #includes into a file called stdafx.h and it is compiled once instead of everywhere that it is included, in order to speed up your compilation. Just remove the #include "stdafx.h" from the code.

  3. #3
    Registered User Osaou's Avatar
    Join Date
    Nov 2004
    Location
    Stockholm, Sweden
    Posts
    69
    And the following code will compile, but is erroneous:
    Code:
    TextOut(hDC,150,150,string, sizeof(string)-1);
    The correct way (I atleast assume this is what you want) would be:
    Code:
    TextOut(hDC,150,150,string, strlen(string)-1);

  4. #4
    Registered User
    Join Date
    Jul 2006
    Posts
    2
    wow, thanks for all the fast responses, I also got these errors that won't let me compile the script:

    C:\Dev-Cpp\my programs\1\Untitled1.cpp In function `int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)':
    [Linker error] undefined reference to `SetTextColor@8'
    [Linker error] undefined reference to `TextOutA@20'
    [Linker error] undefined reference to `GetStockObject@4'
    90 C:\DOCUME~1\Joseph\LOCALS~1\Temp\cciIbaaa.o(.text+ 0x198) ld returned 1 exit status
    Not quite sure what they mean, or how to fix them

  5. #5
    Registered User
    Join Date
    Oct 2005
    Posts
    82
    Yep try the tutorial myself in Dev c++

    to get the last one to work you need to link (not the one posted)

    I had to link these libraries:

    ../../../../Dev-Cpp/lib/libglaux.a
    ../../../../Dev-Cpp/lib/libglu32.a
    ../../../../Dev-Cpp/lib/libopengl32.a
    ../../../../Dev-Cpp/lib/libgdi32.a

    and also

    //#include <gl/glaux.h>

    you may have to do something similar but i couldn't honestly tell you, search the boards though there is another thread on it.

    good luck

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling issue with the OpenGL tutorial by RoD
    By Twitchmokey in forum Game Programming
    Replies: 12
    Last Post: 06-26-2006, 06:05 PM
  2. My new website
    By joeprogrammer in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 03-17-2006, 07:38 PM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  4. SDL_ttf and OpenGL
    By sand_man in forum Game Programming
    Replies: 2
    Last Post: 12-01-2004, 06:06 PM