• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By fleissi
      Hey guys!

      I'm new here and I recently started developing my own rendering engine. It's open source, based on OpenGL/DirectX and C++.
      The full source code is hosted on github:
      https://github.com/fleissna/flyEngine

      I would appreciate if people with experience in game development / engine desgin could take a look at my source code. I'm looking for honest, constructive criticism on how to improve the engine.
      I'm currently writing my master's thesis in computer science and in the recent year I've gone through all the basics about graphics programming, learned DirectX and OpenGL, read some articles on Nvidia GPU Gems, read books and integrated some of this stuff step by step into the engine.

      I know about the basics, but I feel like there is some missing link that I didn't get yet to merge all those little pieces together.

      Features I have so far:
      - Dynamic shader generation based on material properties
      - Dynamic sorting of meshes to be renderd based on shader and material
      - Rendering large amounts of static meshes
      - Hierarchical culling (detail + view frustum)
      - Limited support for dynamic (i.e. moving) meshes
      - Normal, Parallax and Relief Mapping implementations
      - Wind animations based on vertex displacement
      - A very basic integration of the Bullet physics engine
      - Procedural Grass generation
      - Some post processing effects (Depth of Field, Light Volumes, Screen Space Reflections, God Rays)
      - Caching mechanisms for textures, shaders, materials and meshes

      Features I would like to have:
      - Global illumination methods
      - Scalable physics
      - Occlusion culling
      - A nice procedural terrain generator
      - Scripting
      - Level Editing
      - Sound system
      - Optimization techniques

      Books I have so far:
      - Real-Time Rendering Third Edition
      - 3D Game Programming with DirectX 11
      - Vulkan Cookbook (not started yet)

      I hope you guys can take a look at my source code and if you're really motivated, feel free to contribute :-)
      There are some videos on youtube that demonstrate some of the features:
      Procedural grass on the GPU
      Procedural Terrain Engine
      Quadtree detail and view frustum culling

      The long term goal is to turn this into a commercial game engine. I'm aware that this is a very ambitious goal, but I'm sure it's possible if you work hard for it.

      Bye,

      Phil
    • By tj8146
      I have attached my project in a .zip file if you wish to run it for yourself.
      I am making a simple 2d top-down game and I am trying to run my code to see if my window creation is working and to see if my timer is also working with it. Every time I run it though I get errors. And when I fix those errors, more come, then the same errors keep appearing. I end up just going round in circles.  Is there anyone who could help with this? 
       
      Errors when I build my code:
      1>Renderer.cpp 1>c:\users\documents\opengl\game\game\renderer.h(15): error C2039: 'string': is not a member of 'std' 1>c:\program files (x86)\windows kits\10\include\10.0.16299.0\ucrt\stddef.h(18): note: see declaration of 'std' 1>c:\users\documents\opengl\game\game\renderer.h(15): error C2061: syntax error: identifier 'string' 1>c:\users\documents\opengl\game\game\renderer.cpp(28): error C2511: 'bool Game::Rendering::initialize(int,int,bool,std::string)': overloaded member function not found in 'Game::Rendering' 1>c:\users\documents\opengl\game\game\renderer.h(9): note: see declaration of 'Game::Rendering' 1>c:\users\documents\opengl\game\game\renderer.cpp(35): error C2597: illegal reference to non-static member 'Game::Rendering::window' 1>c:\users\documents\opengl\game\game\renderer.cpp(36): error C2597: illegal reference to non-static member 'Game::Rendering::window' 1>c:\users\documents\opengl\game\game\renderer.cpp(43): error C2597: illegal reference to non-static member 'Game::Rendering::window' 1>Done building project "Game.vcxproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========  
       
      Renderer.cpp
      #include <GL/glew.h> #include <GLFW/glfw3.h> #include "Renderer.h" #include "Timer.h" #include <iostream> namespace Game { GLFWwindow* window; /* Initialize the library */ Rendering::Rendering() { mClock = new Clock; } Rendering::~Rendering() { shutdown(); } bool Rendering::initialize(uint width, uint height, bool fullscreen, std::string window_title) { if (!glfwInit()) { return -1; } /* Create a windowed mode window and its OpenGL context */ window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL); if (!window) { glfwTerminate(); return -1; } /* Make the window's context current */ glfwMakeContextCurrent(window); glViewport(0, 0, (GLsizei)width, (GLsizei)height); glOrtho(0, (GLsizei)width, (GLsizei)height, 0, 1, -1); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glfwSwapInterval(1); glEnable(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glEnable(GL_TEXTURE_2D); glLoadIdentity(); return true; } bool Rendering::render() { /* Loop until the user closes the window */ if (!glfwWindowShouldClose(window)) return false; /* Render here */ mClock->reset(); glfwPollEvents(); if (mClock->step()) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glfwSwapBuffers(window); mClock->update(); } return true; } void Rendering::shutdown() { glfwDestroyWindow(window); glfwTerminate(); } GLFWwindow* Rendering::getCurrentWindow() { return window; } } Renderer.h
      #pragma once namespace Game { class Clock; class Rendering { public: Rendering(); ~Rendering(); bool initialize(uint width, uint height, bool fullscreen, std::string window_title = "Rendering window"); void shutdown(); bool render(); GLFWwindow* getCurrentWindow(); private: GLFWwindow * window; Clock* mClock; }; } Timer.cpp
      #include <GL/glew.h> #include <GLFW/glfw3.h> #include <time.h> #include "Timer.h" namespace Game { Clock::Clock() : mTicksPerSecond(50), mSkipTics(1000 / mTicksPerSecond), mMaxFrameSkip(10), mLoops(0) { mLastTick = tick(); } Clock::~Clock() { } bool Clock::step() { if (tick() > mLastTick && mLoops < mMaxFrameSkip) return true; return false; } void Clock::reset() { mLoops = 0; } void Clock::update() { mLastTick += mSkipTics; mLoops++; } clock_t Clock::tick() { return clock(); } } TImer.h
      #pragma once #include "Common.h" namespace Game { class Clock { public: Clock(); ~Clock(); void update(); bool step(); void reset(); clock_t tick(); private: uint mTicksPerSecond; ufloat mSkipTics; uint mMaxFrameSkip; uint mLoops; uint mLastTick; }; } Common.h
      #pragma once #include <cstdio> #include <cstdlib> #include <ctime> #include <cstring> #include <cmath> #include <iostream> namespace Game { typedef unsigned char uchar; typedef unsigned short ushort; typedef unsigned int uint; typedef unsigned long ulong; typedef float ufloat; }  
      Game.zip
    • By lxjk
      Hi guys,
      There are many ways to do light culling in tile-based shading. I've been playing with this idea for a while, and just want to throw it out there.
      Because tile frustums are general small compared to light radius, I tried using cone test to reduce false positives introduced by commonly used sphere-frustum test.
      On top of that, I use distance to camera rather than depth for near/far test (aka. sliced by spheres).
      This method can be naturally extended to clustered light culling as well.
      The following image shows the general ideas

       
      Performance-wise I get around 15% improvement over sphere-frustum test. You can also see how a single light performs as the following: from left to right (1) standard rendering of a point light; then tiles passed the test of (2) sphere-frustum test; (3) cone test; (4) spherical-sliced cone test
       

       
      I put the details in my blog post (https://lxjk.github.io/2018/03/25/Improve-Tile-based-Light-Culling-with-Spherical-sliced-Cone.html), GLSL source code included!
       
      Eric
    • By Fadey Duh
      Good evening everyone!

      I was wondering if there is something equivalent of  GL_NV_blend_equation_advanced for AMD?
      Basically I'm trying to find more compatible version of it.

      Thank you!
    • By Jens Eckervogt
      Hello guys, 
       
      Please tell me! 
      How do I know? Why does wavefront not show for me?
      I already checked I have non errors yet.
      using OpenTK; using System.Collections.Generic; using System.IO; using System.Text; namespace Tutorial_08.net.sourceskyboxer { public class WaveFrontLoader { private static List<Vector3> inPositions; private static List<Vector2> inTexcoords; private static List<Vector3> inNormals; private static List<float> positions; private static List<float> texcoords; private static List<int> indices; public static RawModel LoadObjModel(string filename, Loader loader) { inPositions = new List<Vector3>(); inTexcoords = new List<Vector2>(); inNormals = new List<Vector3>(); positions = new List<float>(); texcoords = new List<float>(); indices = new List<int>(); int nextIdx = 0; using (var reader = new StreamReader(File.Open("Contents/" + filename + ".obj", FileMode.Open), Encoding.UTF8)) { string line = reader.ReadLine(); int i = reader.Read(); while (true) { string[] currentLine = line.Split(); if (currentLine[0] == "v") { Vector3 pos = new Vector3(float.Parse(currentLine[1]), float.Parse(currentLine[2]), float.Parse(currentLine[3])); inPositions.Add(pos); if (currentLine[1] == "t") { Vector2 tex = new Vector2(float.Parse(currentLine[1]), float.Parse(currentLine[2])); inTexcoords.Add(tex); } if (currentLine[1] == "n") { Vector3 nom = new Vector3(float.Parse(currentLine[1]), float.Parse(currentLine[2]), float.Parse(currentLine[3])); inNormals.Add(nom); } } if (currentLine[0] == "f") { Vector3 pos = inPositions[0]; positions.Add(pos.X); positions.Add(pos.Y); positions.Add(pos.Z); Vector2 tc = inTexcoords[0]; texcoords.Add(tc.X); texcoords.Add(tc.Y); indices.Add(nextIdx); ++nextIdx; } reader.Close(); return loader.loadToVAO(positions.ToArray(), texcoords.ToArray(), indices.ToArray()); } } } } } And It have tried other method but it can't show for me.  I am mad now. Because any OpenTK developers won't help me.
      Please help me how do I fix.

      And my download (mega.nz) should it is original but I tried no success...
      - Add blend source and png file here I have tried tried,.....  
       
      PS: Why is our community not active? I wait very longer. Stop to lie me!
      Thanks !
  • Advertisement
  • Advertisement

Archived

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

OpenGL multi window with opengl

This topic is 5369 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 have created two windows, but my (simple... i hope) problem is to draw into them. Do we have some function to tell OpenGL to render INTO a particular window? (switch between more wnds) possible send HWND or HDC? how? please help, i have no idea...

Share this post


Link to post
Share on other sites
Advertisement
As far as I know OpenGL will always render into the window which is in the same thread. Don''t know of any parameters to pass... Never tried what happens if you have two windows in the same thread, but you could just create two threads, give each it''s own window and gl-commands?

Share this post


Link to post
Share on other sites
no, I think that OpenGL library (=dll) is loaded only once for INSTANCE, threads are only using imported funcs.
idea (maybe helpful) what exactly does wglMakeCurrent() and wglCreateContext() and that third wgl_something_()? I never thought about them.

Share this post


Link to post
Share on other sites
quote:
from MSDN The wglMakeCurrent function makes a specified OpenGL rendering context the calling thread''s current rendering context. All subsequent OpenGL calls made by the thread are drawn on the device identified by hdc. You can also use wglMakeCurrent to change the calling thread''s current rendering context so it''s no longer current.

So, if you have two threads, each OpenGL call inside the thread will be made to the opengl rendering context of that thread. The other stuff is for creating a rendering context and binding it to a window.

Share this post


Link to post
Share on other sites
This should help, it renders 4 opengl screens each in an edit control in a dialogbox. Plus this is in Win32 API
What you can basically do with this is create windows within your window, get their DCs and Wiggles then render.

Main Source File

// windowopengl.cpp : Defines the entry point for the application.

//


#include "stdafx.h"
#include "resource.h"
#include <gl\glut.h>
#include <gl\gl.h>
#include <gl\glaux.h>

#define MAX_LOADSTRING 100

// Global Variables:

HINSTANCE hInst; // current instance

TCHAR szTitle[MAX_LOADSTRING]; // The title bar text

TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text

int TheEnd; // Flag used by thread to end

int xrot; // rotation


// Foward declarations of functions included in this code module:

ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK OpenGL(HWND, UINT, WPARAM, LPARAM);
DWORD WINAPI InitGL(HWND);
int MySetPixelFormat(HDC hdc);
void RenderScene(int);

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.

MSG msg;
HACCEL hAccelTable;

// Initialize global strings

LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_WINDOWOPENGL, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

// Perform application initialization:

if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_WINDOWOPENGL);

// Main message loop:

while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return msg.wParam;
}



//

// FUNCTION: MyRegisterClass()

//

// PURPOSE: Registers the window class.

//

// COMMENTS:

//

// This function and its usage is only necessary if you want this code

// to be compatible with Win32 systems prior to the 'RegisterClassEx'

// function that was added to Windows 95. It is important to call this function

// so that the application will get 'well formed' small icons associated

// with it.

//

ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_WINDOWOPENGL);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = (LPCSTR)IDC_WINDOWOPENGL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

return RegisterClassEx(&wcex);
}

//

// FUNCTION: InitInstance(HANDLE, int)

//

// PURPOSE: Saves instance handle and creates main window

//

// COMMENTS:

//

// In this function, we save the instance handle in a global variable and

// create and display the main program window.

//

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;

hInst = hInstance; // Store instance handle in our global variable


hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

if (!hWnd)
{
return FALSE;
}

ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

return TRUE;
}

//

// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)

//

// PURPOSE: Processes messages for the main window.

//

// WM_COMMAND - process the application menu

// WM_PAINT - Paint the main window

// WM_DESTROY - post a quit message and return

//

//

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
TCHAR szHello[MAX_LOADSTRING];
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);

switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:

switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
case IDM_OPENGL:
DialogBox(hInst, (LPCTSTR)IDD_OPENGL, hWnd, (DLGPROC)OpenGL);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...

RECT rt;
GetClientRect(hWnd, &rt);
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

// Mesage handler for about box.

LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;

case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}

// Mesage handler for OpenGL box.

LRESULT CALLBACK OpenGL(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
static HANDLE hOpenGL;
static DWORD lpThreadId;

switch (message)
{
case WM_INITDIALOG:
return TRUE;

case WM_COMMAND:
if (LOWORD(wParam) == IDOK)
{
TheEnd=1;
Sleep(500);
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
if (LOWORD(wParam) == IDRENDER)
{

EnableWindow(GetDlgItem(hDlg,IDRENDER),FALSE);
hOpenGL=CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)InitGL,hDlg,0,&lpThreadId);

}
break;
}
return FALSE;
}


// Here, we do the regular initialization of OpenGL

DWORD WINAPI InitGL(HWND hDlg)
{
HDC hDC1,hDC2,hDC3,hDC4;
HWND hEdit1,hEdit2,hEdit3,hEdit4;
HGLRC hglrc1,hglrc2,hglrc3,hglrc4;

// First, let's get the handle to all the window we created in the Dialog

// with the resource editor

hEdit1=GetDlgItem(hDlg,IDC_EDIT1);
hEdit2=GetDlgItem(hDlg,IDC_EDIT2);
hEdit3=GetDlgItem(hDlg,IDC_EDIT3);
hEdit4=GetDlgItem(hDlg,IDC_EDIT4);

// For every window, we get the HDC

hDC1=GetDC(hEdit1);
hDC2=GetDC(hEdit2);
hDC3=GetDC(hEdit3);
hDC4=GetDC(hEdit4);

// OpenGL Initialization

glShadeModel(GL_SMOOTH); // Enable Smooth Shading

glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background

glClearDepth(1.0f); // Depth Buffer Setup

glEnable(GL_DEPTH_TEST); // Enables Depth Testing

glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do

glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations


MySetPixelFormat(hDC1);
MySetPixelFormat(hDC2);
MySetPixelFormat(hDC3);
MySetPixelFormat(hDC4);

hglrc1 = wglCreateContext(hDC1);
hglrc2 = wglCreateContext(hDC2);
hglrc3 = wglCreateContext(hDC3);
hglrc4 = wglCreateContext(hDC4);

//render here

while(TheEnd !=1 )
{

// Select first Window as the rendering context and draw to it

wglMakeCurrent(hDC1, hglrc1);
RenderScene(1);
SwapBuffers(hDC1);

// Select second Window as the rendering context and draw to it

wglMakeCurrent(hDC2, hglrc2);
RenderScene(2);
SwapBuffers(hDC2);

// Select third Window as the rendering context and draw to it

wglMakeCurrent(hDC3, hglrc3);
RenderScene(2);
SwapBuffers(hDC3);

// Select fourth Window as the rendering context and draw to it

wglMakeCurrent(hDC4, hglrc4);
RenderScene(1);
SwapBuffers(hDC4);

// Throttle the loop. If we don't put a sleep here, the thread will use 100% cpu

Sleep(1);
}

wglMakeCurrent(NULL, NULL);

// Cleanup

ReleaseDC (hDlg, hDC1) ;
ReleaseDC (hDlg, hDC2) ;
ReleaseDC (hDlg, hDC3) ;
ReleaseDC (hDlg, hDC4) ;

wglDeleteContext(hglrc1);
wglDeleteContext(hglrc2);
wglDeleteContext(hglrc3);
wglDeleteContext(hglrc4);

return TRUE;
}

// Set up the pixel format

int MySetPixelFormat(HDC hdc)
{


PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd

1, // version number

PFD_DRAW_TO_WINDOW | // support window

PFD_SUPPORT_OPENGL | // support OpenGL

PFD_DOUBLEBUFFER, // double buffered

PFD_TYPE_RGBA, // RGBA type

24, // 24-bit 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, // accum bits ignored

32, // 32-bit z-buffer

0, // no stencil buffer

0, // no auxiliary buffer

PFD_MAIN_PLANE, // main layer

0, // reserved

0, 0, 0 // layer masks ignored

};

int iPixelFormat;

// get the device context's best, available pixel format match

if((iPixelFormat = ChoosePixelFormat(hdc, &pfd)) == 0)
{
MessageBox(NULL, "ChoosePixelFormat Failed", NULL, MB_OK);
return 0;
}

// make that match the device context's current pixel format

if(SetPixelFormat(hdc, iPixelFormat, &pfd) == FALSE)
{
MessageBox(NULL, "SetPixelFormat Failed", NULL, MB_OK);
return 0;
}

return 1;
}


// This is where we render, in this case, we will draw a simple 3D-Triangle

void RenderScene(int axis)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

if(axis==1) glRotatef(xrot,1.0f,0.0f,0.0f);
if(axis==2) glRotatef(xrot,0.0f,1.0f,0.0f);

glBegin(GL_TRIANGLES);
glColor3f(1, 0, 0);
glVertex3f(0, 0.8f, 0); //top

glColor3f(0, 1, 0);
glVertex3f(-0.5, -0.5, 0.5); //left

glColor3f(0, 0,1);
glVertex3f(0.5, -0.5, 0.5); //right



glColor3f(1.0f,0.0f,0.0f); // Red

glVertex3f( 0.0f, 0.8f, 0.0f); // Top Of Triangle (Right)

glColor3f(0.0f,0.0f,1.0f); // Blue

glVertex3f( .5f,-.5f, .5f); // Left Of Triangle (Right)

glColor3f(0.0f,0.5f,0.0f); // Green

glVertex3f( 0.5f,-0.5f, -0.5f); // Right Of Triangle (Right)


glColor3f(1.0f,0.0f,0.0f); // Red

glVertex3f( 0.0f, 0.8f, 0.0f); // Top Of Triangle (Back)

glColor3f(0.0f,1.0f,0.0f); // Green

glVertex3f( 0.5f,-0.5f, -0.5f); // Left Of Triangle (Back)

glColor3f(0.0f,0.0f,1.0f); // Blue

glVertex3f(-0.5f,-0.5f, -0.5f); // Right Of Triangle (Back)


glColor3f(1.0f,0.0f,0.0f); // Red

glVertex3f( 0.0f, 0.8f, 0.0f); // Top Of Triangle (Left)

glColor3f(0.0f,0.0f,1.0f); // Blue

glVertex3f(-0.5f,-0.5f,-0.5f); // Left Of Triangle (Left)

glColor3f(0.0f,1.0f,0.0f); // Green

glVertex3f(-0.5f,-0.5f, 0.5f); // Right Of Triangle (Left)


glEnd();

xrot+=1.5f;

}


Resource ID file

//{{NO_DEPENDENCIES}}

// Microsoft Developer Studio generated include file.

// Used by windowopengl.rc

//

#define IDC_MYICON 2
#define IDD_WINDOWOPENGL_DIALOG 102
#define IDD_ABOUTBOX 103
#define IDS_APP_TITLE 103
#define IDM_ABOUT 104
#define IDM_EXIT 105
#define IDS_HELLO 106
#define IDI_WINDOWOPENGL 107
#define IDI_SMALL 108
#define IDC_WINDOWOPENGL 109
#define IDR_MAINFRAME 128
#define IDD_OPENGL 129
#define IDC_EDIT1 1000
#define IDRENDER 1001
#define IDC_EDIT2 1002
#define IDC_EDIT3 1003
#define IDC_EDIT4 1004
#define IDM_OPENGL 32771
#define IDC_STATIC -1

// Next default values for new objects

//

#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 130
#define _APS_NEXT_COMMAND_VALUE 32772
#define _APS_NEXT_CONTROL_VALUE 1002
#define _APS_NEXT_SYMED_VALUE 110
#endif
#endif


Resource File

//Microsoft Developer Studio generated resource script.

//

#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////

//

// Generated from the TEXTINCLUDE 2 resource.

//

#define APSTUDIO_HIDDEN_SYMBOLS
#include "windows.h"
#undef APSTUDIO_HIDDEN_SYMBOLS
#include "resource.h"

/////////////////////////////////////////////////////////////////////////////

#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////

// English (U.S.) resources


#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32


/////////////////////////////////////////////////////////////////////////////

//

// Icon

//


// Icon with lowest ID value placed first to ensure application icon

// remains consistent on all systems.

IDI_WINDOWOPENGL ICON DISCARDABLE "windowopengl.ICO"
IDI_SMALL ICON DISCARDABLE "SMALL.ICO"

/////////////////////////////////////////////////////////////////////////////

//

// Menu

//


IDC_WINDOWOPENGL MENU DISCARDABLE
BEGIN
POPUP "&File"
BEGIN
MENUITEM "E&xit", IDM_EXIT
END
MENUITEM "&OpenGL", IDM_OPENGL
POPUP "&Help"
BEGIN
MENUITEM "&About ...", IDM_ABOUT
END
END


/////////////////////////////////////////////////////////////////////////////

//

// Accelerator

//


IDC_WINDOWOPENGL ACCELERATORS MOVEABLE PURE
BEGIN
"?", IDM_ABOUT, ASCII, ALT
"/", IDM_ABOUT, ASCII, ALT
END


/////////////////////////////////////////////////////////////////////////////

//

// Dialog

//


IDD_ABOUTBOX DIALOG DISCARDABLE 22, 17, 230, 75
STYLE DS_MODALFRAME | WS_CAPTION | WS_SYSMENU
CAPTION "About"
FONT 8, "System"
BEGIN
ICON IDI_WINDOWOPENGL,IDC_MYICON,14,9,16,16
LTEXT "windowopengl Version 1.0",IDC_STATIC,49,10,119,8,
SS_NOPREFIX
LTEXT "Copyright (C) 2001",IDC_STATIC,49,20,119,8
DEFPUSHBUTTON "OK",IDOK,195,6,30,11,WS_GROUP
END

IDD_OPENGL DIALOG DISCARDABLE 0, 0, 304, 170
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Window OpenGL example by Chong Hin Ooi, chongooi@mediaone.net"
FONT 8, "MS Sans Serif"
BEGIN
DEFPUSHBUTTON "Render",IDRENDER,190,149,50,14
PUSHBUTTON "OK",IDOK,247,149,50,14
EDITTEXT IDC_EDIT1,7,7,138,58,ES_AUTOHSCROLL
EDITTEXT IDC_EDIT2,159,7,138,58,ES_AUTOHSCROLL
EDITTEXT IDC_EDIT3,7,78,138,58,ES_AUTOHSCROLL
EDITTEXT IDC_EDIT4,159,78,138,58,ES_AUTOHSCROLL
END


#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////

//

// TEXTINCLUDE

//


2 TEXTINCLUDE DISCARDABLE
BEGIN
"#define APSTUDIO_HIDDEN_SYMBOLS\r\n"
"#include ""windows.h""\r\n"
"#undef APSTUDIO_HIDDEN_SYMBOLS\r\n"
"#include ""resource.h""\r\n"
"\0"
END

3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END

1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END

#endif // APSTUDIO_INVOKED



/////////////////////////////////////////////////////////////////////////////

//

// DESIGNINFO

//


#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
IDD_OPENGL, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 297
TOPMARGIN, 7
BOTTOMMARGIN, 163
END
END
#endif // APSTUDIO_INVOKED



/////////////////////////////////////////////////////////////////////////////

//

// String Table

//


STRINGTABLE DISCARDABLE
BEGIN
IDS_APP_TITLE "windowopengl"
IDS_HELLO "Window OpenGL example by Chong Hin Ooi"
IDC_WINDOWOPENGL "WINDOWOPENGL"
END

#endif // English (U.S.) resources

/////////////////////////////////////////////////////////////////////////////




#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////

//

// Generated from the TEXTINCLUDE 3 resource.

//



/////////////////////////////////////////////////////////////////////////////

#endif // not APSTUDIO_INVOKED




Hope that helps.
[edit] Misspelled a tag.

[edited by - Xiachunyi on August 11, 2003 11:59:02 AM]

Share this post


Link to post
Share on other sites
Like the above poster''s example shows... Just create a new OpenGL context for each window and then use wglMakeCurrent and then swap the buffers and then repeat for each window.

Share this post


Link to post
Share on other sites
the above two are right. my last renderer used 9 windows (VCL)


OpenGL renders in the selected context in the current thread.

If you have two windows and only need to rendere in one of them at a time, create a context for both and then use wglmakecurrent to select which you wish to render in.

if you want to have both windows being rendered into at the same time, you can either swap the current context between the two (a bit dodgey, but hey, it works) or you can do it the better way and create a two threads. In each thread you have a seperate opengl thread that renders to one of the windows.

Either way, under win32 OpenGL always renders into the THREADS current device context.

I have no idea about macos or os2 or solaris or linux or dos though. I never played with opengl that much under them.

Share this post


Link to post
Share on other sites

  • Advertisement