Win32 API 日本語リファレンス
ホームGraphics.OpenGL › glDrawElements

glDrawElements

関数
インデックス配列を用いてプリミティブを描画する。
DLLOPENGL32.dll呼出規約winapi

シグネチャ

// OPENGL32.dll
#include <windows.h>

void glDrawElements(
    DWORD mode,
    INT count,
    DWORD type,
    const void* indices
);

パラメーター

名前方向説明
modeDWORDin描画するプリミティブ種別。GL_TRIANGLES/GL_TRIANGLE_STRIPなどを指定する。
countINTin描画する要素(インデックス)の数。
typeDWORDinインデックスのデータ型。GL_UNSIGNED_BYTE/GL_UNSIGNED_SHORT/GL_UNSIGNED_INTのいずれか。
indicesvoid*inインデックス配列へのポインタ。バッファオブジェクト使用時はオフセットとして扱う。

戻り値の型: void

各言語での呼び出し定義

// OPENGL32.dll
#include <windows.h>

void glDrawElements(
    DWORD mode,
    INT count,
    DWORD type,
    const void* indices
);
[DllImport("OPENGL32.dll", ExactSpelling = true)]
static extern void glDrawElements(
    uint mode,   // DWORD
    int count,   // INT
    uint type,   // DWORD
    IntPtr indices   // void*
);
<DllImport("OPENGL32.dll", ExactSpelling:=True)>
Public Shared Sub glDrawElements(
    mode As UInteger,   ' DWORD
    count As Integer,   ' INT
    type As UInteger,   ' DWORD
    indices As IntPtr   ' void*
)
End Sub
' mode : DWORD
' count : INT
' type : DWORD
' indices : void*
Declare PtrSafe Sub glDrawElements Lib "opengl32" ( _
    ByVal mode As Long, _
    ByVal count As Long, _
    ByVal type As Long, _
    ByVal indices As LongPtr)
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

glDrawElements = ctypes.windll.opengl32.glDrawElements
glDrawElements.restype = None
glDrawElements.argtypes = [
    wintypes.DWORD,  # mode : DWORD
    ctypes.c_int,  # count : INT
    wintypes.DWORD,  # type : DWORD
    ctypes.POINTER(None),  # indices : void*
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('OPENGL32.dll')
glDrawElements = Fiddle::Function.new(
  lib['glDrawElements'],
  [
    -Fiddle::TYPE_INT,  # mode : DWORD
    Fiddle::TYPE_INT,  # count : INT
    -Fiddle::TYPE_INT,  # type : DWORD
    Fiddle::TYPE_VOIDP,  # indices : void*
  ],
  Fiddle::TYPE_VOID)
#[link(name = "opengl32")]
extern "system" {
    fn glDrawElements(
        mode: u32,  // DWORD
        count: i32,  // INT
        type: u32,  // DWORD
        indices: *const ()  // void*
    );
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("OPENGL32.dll")]
public static extern void glDrawElements(uint mode, int count, uint type, IntPtr indices);
"@
$api = Add-Type -MemberDefinition $sig -Name 'OPENGL32_glDrawElements' -Namespace Win32 -PassThru
# $api::glDrawElements(mode, count, type, indices)
#uselib "OPENGL32.dll"
#func global glDrawElements "glDrawElements" sptr, sptr, sptr, sptr
; glDrawElements mode, count, type, indices
; mode : DWORD -> "sptr"
; count : INT -> "sptr"
; type : DWORD -> "sptr"
; indices : void* -> "sptr"
#uselib "OPENGL32.dll"
#func global glDrawElements "glDrawElements" int, int, int, sptr
; glDrawElements mode, count, type, indices
; mode : DWORD -> "int"
; count : INT -> "int"
; type : DWORD -> "int"
; indices : void* -> "sptr"
; void glDrawElements(DWORD mode, INT count, DWORD type, void* indices)
#uselib "OPENGL32.dll"
#func global glDrawElements "glDrawElements" int, int, int, intptr
; glDrawElements mode, count, type, indices
; mode : DWORD -> "int"
; count : INT -> "int"
; type : DWORD -> "int"
; indices : void* -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	opengl32 = windows.NewLazySystemDLL("OPENGL32.dll")
	procglDrawElements = opengl32.NewProc("glDrawElements")
)

// mode (DWORD), count (INT), type (DWORD), indices (void*)
r1, _, err := procglDrawElements.Call(
	uintptr(mode),
	uintptr(count),
	uintptr(type),
	uintptr(indices),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // void
procedure glDrawElements(
  mode: DWORD;   // DWORD
  count: Integer;   // INT
  type: DWORD;   // DWORD
  indices: Pointer   // void*
); stdcall;
  external 'OPENGL32.dll' name 'glDrawElements';
result := DllCall("OPENGL32\glDrawElements"
    , "UInt", mode   ; DWORD
    , "Int", count   ; INT
    , "UInt", type   ; DWORD
    , "Ptr", indices   ; void*
    , "Int")   ; return: void
●glDrawElements(mode, count, type, indices) = DLL("OPENGL32.dll", "int glDrawElements(dword, int, dword, void*)")
# 呼び出し: glDrawElements(mode, count, type, indices)
# mode : DWORD -> "dword"
# count : INT -> "int"
# type : DWORD -> "dword"
# indices : void* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "opengl32" fn glDrawElements(
    mode: u32, // DWORD
    count: i32, // INT
    type: u32, // DWORD
    indices: ?*anyopaque // void*
) callconv(std.os.windows.WINAPI) void;
proc glDrawElements(
    mode: uint32,  # DWORD
    count: int32,  # INT
    `type`: uint32,  # DWORD
    indices: pointer  # void*
) {.importc: "glDrawElements", stdcall, dynlib: "OPENGL32.dll".}
pragma(lib, "opengl32");
extern(Windows)
void glDrawElements(
    uint mode,   // DWORD
    int count,   // INT
    uint type,   // DWORD
    void* indices   // void*
);
ccall((:glDrawElements, "OPENGL32.dll"), stdcall, Cvoid,
      (UInt32, Int32, UInt32, Ptr{Cvoid}),
      mode, count, type, indices)
# mode : DWORD -> UInt32
# count : INT -> Int32
# type : DWORD -> UInt32
# indices : void* -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
void glDrawElements(
    uint32_t mode,
    int32_t count,
    uint32_t type,
    void* indices);
]]
local opengl32 = ffi.load("opengl32")
-- opengl32.glDrawElements(mode, count, type, indices)
-- mode : DWORD
-- count : INT
-- type : DWORD
-- indices : void*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('OPENGL32.dll');
const glDrawElements = lib.func('__stdcall', 'glDrawElements', 'void', ['uint32_t', 'int32_t', 'uint32_t', 'void *']);
// glDrawElements(mode, count, type, indices)
// mode : DWORD -> 'uint32_t'
// count : INT -> 'int32_t'
// type : DWORD -> 'uint32_t'
// indices : void* -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("OPENGL32.dll", {
  glDrawElements: { parameters: ["u32", "i32", "u32", "pointer"], result: "void" },
});
// lib.symbols.glDrawElements(mode, count, type, indices)
// mode : DWORD -> "u32"
// count : INT -> "i32"
// type : DWORD -> "u32"
// indices : void* -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
void glDrawElements(
    uint32_t mode,
    int32_t count,
    uint32_t type,
    void* indices);
C, "OPENGL32.dll");
// $ffi->glDrawElements(mode, count, type, indices);
// mode : DWORD
// count : INT
// type : DWORD
// indices : void*
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Opengl32 extends StdCallLibrary {
    Opengl32 INSTANCE = Native.load("opengl32", Opengl32.class);
    void glDrawElements(
        int mode,   // DWORD
        int count,   // INT
        int type,   // DWORD
        Pointer indices   // void*
    );
}
@[Link("opengl32")]
lib LibOPENGL32
  fun glDrawElements = glDrawElements(
    mode : UInt32,   # DWORD
    count : Int32,   # INT
    type_ : UInt32,   # DWORD
    indices : Void*   # void*
  ) : Void
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef glDrawElementsNative = Void Function(Uint32, Int32, Uint32, Pointer<Void>);
typedef glDrawElementsDart = void Function(int, int, int, Pointer<Void>);
final glDrawElements = DynamicLibrary.open('OPENGL32.dll')
    .lookupFunction<glDrawElementsNative, glDrawElementsDart>('glDrawElements');
// mode : DWORD -> Uint32
// count : INT -> Int32
// type : DWORD -> Uint32
// indices : void* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
procedure glDrawElements(
  mode: DWORD;   // DWORD
  count: Integer;   // INT
  type: DWORD;   // DWORD
  indices: Pointer   // void*
); stdcall;
  external 'OPENGL32.dll' name 'glDrawElements';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "glDrawElements"
  c_glDrawElements :: Word32 -> Int32 -> Word32 -> Ptr () -> IO ()
-- mode : DWORD -> Word32
-- count : INT -> Int32
-- type : DWORD -> Word32
-- indices : void* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let gldrawelements =
  foreign "glDrawElements"
    (uint32_t @-> int32_t @-> uint32_t @-> (ptr void) @-> returning void)
(* mode : DWORD -> uint32_t *)
(* count : INT -> int32_t *)
(* type : DWORD -> uint32_t *)
(* indices : void* -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library opengl32 (t "OPENGL32.dll"))
(cffi:use-foreign-library opengl32)

(cffi:defcfun ("glDrawElements" gl-draw-elements :convention :stdcall) :void
  (mode :uint32)   ; DWORD
  (count :int32)   ; INT
  (type :uint32)   ; DWORD
  (indices :pointer))   ; void*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $glDrawElements = Win32::API::More->new('OPENGL32',
    'void glDrawElements(DWORD mode, int count, DWORD type, LPVOID indices)');
# my $ret = $glDrawElements->Call($mode, $count, $type, $indices);
# mode : DWORD -> DWORD
# count : INT -> int
# type : DWORD -> DWORD
# indices : void* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。