Basic opengl Tutorial Written Based on Cod 1

Requirements:

Basic Knowledge of C++

Compile with mircosoft visual studio 6.0

Create a new MSVC6 DLL(Dynamic Link Library) Project

create a new file with name main.cpp and put this in


#include <windows.h>
#include "main.h"
#include "opengl.h"


HMODULE hTtnDll = (NULL);
typedef int (WINAPI *farproc)(void);

BOOL pIsDebuggerPresent(){return false;}FARPROC WINAPI pGetProcAddress (HMODULE hModule, LPCSTR lp)
{
if(HIWORD(lp))
{
if (!strcmp(lp,"GetProcAddress")) return (FARPROC)pGetProcAddress;


else if (!strcmp(lp,"glTexCoordPointer")) return (FARPROC)mani_glTexCoordPointer;

}
return GetProcAddress(hModule, lp);
}
DWORD GetModulePath( HINSTANCE hInst, LPTSTR pszBuffer, DWORD dwSize )
{
DWORD dwLen = GetModuleFileName( hInst, pszBuffer, dwSize );
if( dwLen )
{
while( dwLen && pszBuffer[ dwLen ] != '\\' ) {dwLen--;}
if( dwLen ) {pszBuffer[ dwLen + 1 ] = '\000';}
}
return dwLen;
}

bool WINAPI DllMain(HMODULE hDll, DWORD dwReason, PVOID pvReserved)
{
if(dwReason == DLL_PROCESS_ATTACH)
{
hTtnDll = hDll;
DisableThreadLibraryCalls(hDll);
ReDirectFunction("kernel32.dll", "GetProcAddress", (DWORD)&pGetProcAddress);
return TRUE;
}
return FALSE;
}

void ReDirectFunction(char* strDllName, char* strFunctionName, DWORD newFuncAddy)
{
DWORD dwBackup;
DWORD dwIndex;
DWORD dwOffset;
HMODULE hmHL;
PIMAGE_DATA_DIRECTORY pDataDirectory;
PIMAGE_DOS_HEADER pDosHeader;
PDWORD pdwIAT;
PDWORD pdwINT;
PIMAGE_IMPORT_DESCRIPTOR pImportDescriptor;
PIMAGE_IMPORT_BY_NAME pImportName;
PIMAGE_OPTIONAL_HEADER pOptionalHeader;
PIMAGE_NT_HEADERS pPeHeader;
PSTR strCurrent;
hmHL = GetModuleHandle(NULL);
pDosHeader = PIMAGE_DOS_HEADER(hmHL);
dwOffset = pDosHeader->e_lfanew;
pPeHeader = PIMAGE_NT_HEADERS(LONG(hmHL) + dwOffset);
pOptionalHeader = &pPeHeader->OptionalHeader;
pDataDirectory = pOptionalHeader->DataDirectory;
dwOffset = pDataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress;
pImportDescriptor = PIMAGE_IMPORT_DESCRIPTOR(LONG(hmHL) + dwOffset);
for(dwIndex = 0; true; dwIndex++)
{
dwOffset = pImportDescriptor[dwIndex].Name;
strCurrent = PSTR(LONG(hmHL) + dwOffset);
if(stricmp(strCurrent, strDllName) == 0) break;
}
dwOffset = pImportDescriptor[dwIndex].FirstThunk;
pdwIAT = PDWORD(LONG(hmHL) + dwOffset);
dwOffset = pImportDescriptor[dwIndex].OriginalFirstThunk;
pdwINT = PDWORD(LONG(hmHL) + dwOffset);
for(dwIndex = 0; true; dwIndex++)
{
dwOffset = pdwINT[dwIndex];
pImportName = PIMAGE_IMPORT_BY_NAME(LONG(hmHL) + dwOffset);
strCurrent = PSTR(pImportName->Name);
if(stricmp(strCurrent, strFunctionName) == 0) break;
}
VirtualProtect(&pdwIAT[dwIndex], sizeof(DWORD), PAGE_READWRITE, &dwBackup);
pdwIAT[dwIndex] = PtrToUlong(newFuncAddy);
VirtualProtect(&pdwIAT[dwIndex], sizeof(DWORD), dwBackup, &dwOffset);
}


Create a new fiele with name "main.h"


void ReDirectFunction (char* strDllName, char* strFunctionName, DWORD newFuncAddy);

DWORD GetModulePath (HINSTANCE hInst, LPTSTR pszBuffer, DWORD dwSize);

extern HMODULE hTtnDll;

create a new fiele "opengl.cpp" and put this in


#include <windows.h>
#include "opengl.h"

///////////////////////////////////////////////////////////////////////
int djzuza=1;
////////////////////////////////////////////////////////////////////////
void APIENTRY mani_glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)
{
if (djzuza==1)
{ glEnable(GL_COLOR_MATERIAL);

glEnable(GL_COLOR_MATERIAL);

glColor4f(0.6f, 0.6f, 0.6f, 0.6f); glColor4f(0.6f, 0.6f, 0.6f, 0.6f);

glDepthFunc(GL_LEQUAL);
glEnable(GL_COLOR_MATERIAL);

glColor4f(0.6f, 0.6f, 0.6f, 0.6f);
{ glEnable(GL_COLOR_MATERIAL);

glColor4f(0.6f, 0.6f, 0.6f, 0.6f);

{
if (stride==0)
{ glEnable(GL_COLOR_MATERIAL);

glColor4f(0.6f, 0.6f, 0.6f, 0.6f);
glDepthFunc(GL_ALWAYS);
}
}
}
} glEnable(GL_COLOR_MATERIAL);

glColor4f(0.6f, 0.6f, 0.6f, 0.6f);
(glTexCoordPointer) (size, type, stride, pointer);



{

}

}


create a new fiele "opengl.h" and put this in



#pragma comment(lib,"OpenGL32.lib")
#include <gl/gl.h>



//////////////////////////////////
//Function definitions

void APIENTRY mani_glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);

Done


Credits goes to King-Orgy