Commit cf72c8cd by Maxime Gregoire Committed by Maxime Grégoire

OpenGL 2.1 Simple test cube application

Change-Id: I6609158f6b675082591ebe0f198e43e3218ffc34 Reviewed-on: https://swiftshader-review.googlesource.com/2170Tested-by: 's avatarMaxime Grégoire <mgregoire@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent 574409c2
...@@ -255,6 +255,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OGLES2ColourGrading", "..\t ...@@ -255,6 +255,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OGLES2ColourGrading", "..\t
{E746FCA9-64C3-433E-85E8-9A5A67AB7ED6} = {E746FCA9-64C3-433E-85E8-9A5A67AB7ED6} {E746FCA9-64C3-433E-85E8-9A5A67AB7ED6} = {E746FCA9-64C3-433E-85E8-9A5A67AB7ED6}
EndProjectSection EndProjectSection
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OGLSimpleCube", "..\tests\OGLSimpleCube\OGLSimpleCube.vcxproj", "{27E15292-4A8D-4BA0-8D9B-5D1ECFF85747}"
ProjectSection(ProjectDependencies) = postProject
{3EF851E7-4AAB-4C7C-9A79-3122CEA1EB67} = {3EF851E7-4AAB-4C7C-9A79-3122CEA1EB67}
EndProjectSection
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32 Debug|Win32 = Debug|Win32
...@@ -709,6 +714,15 @@ Global ...@@ -709,6 +714,15 @@ Global
{9F14A82C-19FD-4A8A-B4FF-FF00FFF6F2DD}.Release|Win32.Build.0 = Release|Win32 {9F14A82C-19FD-4A8A-B4FF-FF00FFF6F2DD}.Release|Win32.Build.0 = Release|Win32
{9F14A82C-19FD-4A8A-B4FF-FF00FFF6F2DD}.Release|x64.ActiveCfg = Release|x64 {9F14A82C-19FD-4A8A-B4FF-FF00FFF6F2DD}.Release|x64.ActiveCfg = Release|x64
{9F14A82C-19FD-4A8A-B4FF-FF00FFF6F2DD}.Release|x64.Build.0 = Release|x64 {9F14A82C-19FD-4A8A-B4FF-FF00FFF6F2DD}.Release|x64.Build.0 = Release|x64
{27E15292-4A8D-4BA0-8D9B-5D1ECFF85747}.Debug|Win32.ActiveCfg = Debug|Win32
{27E15292-4A8D-4BA0-8D9B-5D1ECFF85747}.Debug|Win32.Build.0 = Debug|Win32
{27E15292-4A8D-4BA0-8D9B-5D1ECFF85747}.Debug|x64.ActiveCfg = Debug|Win32
{27E15292-4A8D-4BA0-8D9B-5D1ECFF85747}.Profile|Win32.ActiveCfg = Release|Win32
{27E15292-4A8D-4BA0-8D9B-5D1ECFF85747}.Profile|Win32.Build.0 = Release|Win32
{27E15292-4A8D-4BA0-8D9B-5D1ECFF85747}.Profile|x64.ActiveCfg = Release|Win32
{27E15292-4A8D-4BA0-8D9B-5D1ECFF85747}.Release|Win32.ActiveCfg = Release|Win32
{27E15292-4A8D-4BA0-8D9B-5D1ECFF85747}.Release|Win32.Build.0 = Release|Win32
{27E15292-4A8D-4BA0-8D9B-5D1ECFF85747}.Release|x64.ActiveCfg = Release|Win32
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
...@@ -750,5 +764,6 @@ Global ...@@ -750,5 +764,6 @@ Global
{B4537008-1302-4EE7-98C8-6897472B9E36} = {ED25C308-5BDB-43A7-BED6-C2C059FC2D7D} {B4537008-1302-4EE7-98C8-6897472B9E36} = {ED25C308-5BDB-43A7-BED6-C2C059FC2D7D}
{3EF851E7-4AAB-4C7C-9A79-3122CEA1EB67} = {D33114D7-E582-4D61-B27D-FAB0297C43FF} {3EF851E7-4AAB-4C7C-9A79-3122CEA1EB67} = {D33114D7-E582-4D61-B27D-FAB0297C43FF}
{9F14A82C-19FD-4A8A-B4FF-FF00FFF6F2DD} = {ED25C308-5BDB-43A7-BED6-C2C059FC2D7D} {9F14A82C-19FD-4A8A-B4FF-FF00FFF6F2DD} = {ED25C308-5BDB-43A7-BED6-C2C059FC2D7D}
{27E15292-4A8D-4BA0-8D9B-5D1ECFF85747} = {ED25C308-5BDB-43A7-BED6-C2C059FC2D7D}
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal
/******************************************************************************
@File OGLSimpleCube.cpp
@Title OpenGL Simple cube application
@Version 1.0
@Platform Windows
@Description Basic window with a cube drawn in it, using libGL (opengl32).
Inspired by http://www.cs.rit.edu/~ncs/Courses/570/UserGuide/OpenGLonWin-11.html
******************************************************************************/
#include <windows.h>
#include <math.h>
#include <gl\GL.h>
#pragma comment (lib, "opengl32.lib")
#define PI 3.14159265
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
const char *className = "OpenGL";
char *windowName = "OpenGL Cube";
int winX = 0, winY = 0;
int winWidth = 300, winHeight = 300;
int listIndex = 1;
float angle = 1.0f;
double theta = angle * PI / 180.0;
GLfloat R[16] = { 1, 0, 0, 0, 0, cos(theta), -sin(theta), 0, 0, sin(theta), cos(theta), 0, 0, 0, 0, 1 };
HDC hDC;
HGLRC hGLRC;
HPALETTE hPalette;
GLfloat vertices1[] = {
0.5F, 0.5F, 0.5F, -0.5F, 0.5F, 0.5F, -0.5F, -0.5F, 0.5F, 0.5F, -0.5F, 0.5F,
-0.5F, -0.5F, -0.5F, -0.5F, 0.5F, -0.5F, 0.5F, 0.5F, -0.5F, 0.5F, -0.5F, -0.5F,
0.5F, 0.5F, 0.5F, 0.5F, 0.5F, -0.5F, -0.5F, 0.5F, -0.5F, -0.5F, 0.5F, 0.5F,
-0.5F, -0.5F, -0.5F, 0.5F, -0.5F, -0.5F, 0.5F, -0.5F, 0.5F, -0.5F, -0.5F, 0.5F,
0.5F, 0.5F, 0.5F, 0.5F, -0.5F, 0.5F, 0.5F, -0.5F, -0.5F, 0.5F, 0.5F, -0.5F,
-0.5F, -0.5F, -0.5F, -0.5F, -0.5F, 0.5F, -0.5F, 0.5F, 0.5F, -0.5F, 0.5F, -0.5F
};
GLfloat normals1[] = {
0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1,
0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1,
0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0,
0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0,
1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0,
-1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0
};
GLfloat colors1[] = {
1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0,
1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0,
0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0,
0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1
};
void initializeView(void)
{
// Set viewing projection
glMatrixMode(GL_PROJECTION);
glFrustum(-0.5F, 0.5F, -0.5F, 0.5F, 1.0F, 3.0F);
// Position viewer
glMatrixMode(GL_MODELVIEW);
glTranslatef(0.0F, 0.0F, -2.0F);
// Position object
glRotatef(30.0F, 1.0F, 0.0F, 0.0F);
glRotatef(30.0F, 0.0F, 1.0F, 0.0F);
}
void initializeDisplayList(void)
{
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glNormalPointer(GL_FLOAT, 0, normals1);
glColorPointer(3, GL_FLOAT, 0, colors1);
glVertexPointer(3, GL_FLOAT, 0, vertices1);
// Display list
glNewList(listIndex, GL_COMPILE);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glMultMatrixf(R);
glPushMatrix();
glDrawArrays(GL_QUADS, 0, 24);
glPopMatrix();
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glEndList();
}
void redraw(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glCallList(listIndex);
SwapBuffers(hDC);
}
void resize(void)
{
// Set viewport to cover the window
glViewport(0, 0, winWidth, winHeight);
}
void setupPixelFormat(HDC hDC)
{
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), // Size
1, // Version
PFD_SUPPORT_OPENGL |
PFD_DRAW_TO_WINDOW |
PFD_DOUBLEBUFFER, // Support double-buffering
PFD_TYPE_RGBA, // Color type
16, // Prefered color depth
0, 0, 0, 0, 0, 0, // Color bits (ignored)
0, // No alpha buffer
0, // Alpha bits (ignored)
0, // No accumulation buffer
0, 0, 0, 0, // Accum bits (ignored)
16, // Depth buffer
0, // No stencil buffer
0, // No auxiliary buffers
PFD_MAIN_PLANE, // Main layer
0, // Reserved
0, 0, 0, // No layer, visible, damage masks
};
int pixelFormat;
pixelFormat = ChoosePixelFormat(hDC, &pfd);
if(pixelFormat == 0) {
MessageBox(WindowFromDC(hDC), L"ChoosePixelFormat failed.", L"Error",
MB_ICONERROR | MB_OK);
exit(1);
}
if(SetPixelFormat(hDC, pixelFormat, &pfd) != TRUE) {
MessageBox(WindowFromDC(hDC), L"SetPixelFormat failed.", L"Error",
MB_ICONERROR | MB_OK);
exit(1);
}
}
int WinMain(__in HINSTANCE hCurrentInst, __in_opt HINSTANCE hPreviousInst, __in_opt LPSTR lpCmdLine, __in int nShowCmd)
{
WNDCLASS wndClass;
HWND hWnd;
MSG msg;
// Register window class
wndClass.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
wndClass.lpfnWndProc = WndProc;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hInstance = hCurrentInst;
wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.hbrBackground = (HBRUSH)BLACK_BRUSH;
wndClass.lpszMenuName = NULL;
wndClass.lpszClassName = L"OpenGL cube";
RegisterClass(&wndClass);
// Create window
hWnd = CreateWindow(
L"OpenGL cube", L"OpenGL",
WS_OVERLAPPEDWINDOW,
winX, winY, winWidth, winHeight,
NULL, NULL, hCurrentInst, NULL);
// Display window
ShowWindow(hWnd, nShowCmd);
while(true)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if(msg.message == WM_QUIT)
{
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
redraw();
}
}
wglMakeCurrent(NULL, NULL);
wglDeleteContext(hGLRC);
ReleaseDC(hWnd, hDC);
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message) {
case WM_CREATE:
// Initialize OpenGL rendering
hDC = GetDC(hWnd);
setupPixelFormat(hDC);
hGLRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hGLRC);
initializeView();
initializeDisplayList();
return 0;
case WM_DESTROY:
// Finish OpenGL rendering
if(hGLRC) {
wglMakeCurrent(NULL, NULL);
wglDeleteContext(hGLRC);
}
if(hPalette) {
DeleteObject(hPalette);
}
ReleaseDC(hWnd, hDC);
PostQuitMessage(0);
return 0;
case WM_SIZE:
// Track window size changes
if(hGLRC) {
winWidth = (int)LOWORD(lParam);
winHeight = (int)HIWORD(lParam);
resize();
return 0;
}
case WM_PALETTECHANGED:
// Realize palette if this is *not* the current window
if(hGLRC && hPalette && (HWND)wParam != hWnd) {
UnrealizeObject(hPalette);
SelectPalette(hDC, hPalette, FALSE);
RealizePalette(hDC);
redraw();
break;
}
break;
case WM_QUERYNEWPALETTE:
// Realize palette if this is the current window
if(hGLRC && hPalette) {
UnrealizeObject(hPalette);
SelectPalette(hDC, hPalette, FALSE);
RealizePalette(hDC);
return TRUE;
}
break;
default:
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{27E15292-4A8D-4BA0-8D9B-5D1ECFF85747}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>OGLSimpleCube</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>..\..\src\OpenGL\libGL\Win32\Debug\;</AdditionalLibraryDirectories>
<AdditionalDependencies>%(AdditionalDependencies);opengl32.lib</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="OGLSimpleCube.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="OGLSimpleCube.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment