小编pet*_*ter的帖子

为什么不用vec3 for OpenGL ES 2.0 gl_Position?

我是OpenGL ES 2.0的新手,无法理解以下最简单的着色器:

attribute vec4 vPosition;
void main()
{
   gl_Position = vPosition;
}
Run Code Online (Sandbox Code Playgroud)

我的问题是,因为一个位置是一个向量(x, y, z),为什么gl_Position是vec4而不是vec3?

shader opengl-es-2.0

30
推荐指数
2
解决办法
1万
查看次数

如何为特定来电提供定制振动

该程序的功能如下:用户有一个电话号码列表,只有当没有其他系统范围的应用程序提供振动时(例如静音模式),手机才能在来电时振动.我知道这是违反规则的,因为应用程序应该尊重用户的设置,但应用程序仅限于某些具有此需求的用户.我尝试了两种方法,但它们都不令人满意:

  1. 收听电话状态并使用我自己的模式直接触发振动服务(带Vibrator.vibrate()).当手机处于CALL_STATE_RINGING状态时,此方法有效,没有来电但随机有效,我猜这是因为与系统范围的应用程序冲突,实际上处理来电时的振动.

  2. 判断手机是否在来电时振动AudioManager.shouldVibrate(),并决定是否更改振动设置(使用AudioManager.setRingerMode()AudioManager.setVibrateSetting()).如果我的应用程序更改了振动设置,则一旦手机恢复CALL_STATE_IDLE状态,它们将被恢复.然而,这种方法有时仍然无法正常工作,没有任何原因.

我希望有人可以就这个问题提出一些建议.欢迎对这两种方式或其他建议的评论.

android vibration telephonymanager android-audiomanager

22
推荐指数
1
解决办法
1951
查看次数

打印分配的字符串时,valgrind报告错误

代码在这里:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char* buf = malloc(3);
    strcpy(buf, "hi");
    printf("%s\n", buf);
    free(buf);
}
Run Code Online (Sandbox Code Playgroud)

它编译为:

gcc a.c && valgrind ./a.out
Run Code Online (Sandbox Code Playgroud)

错误消息在这里:

==1421== Memcheck, a memory error detector
==1421== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==1421== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info
==1421== Command: ./a.out
==1421== 
==1421== Invalid read of size 8
==1421==    at 0x4EA96C1: ??? (in /lib/libc-2.14.1.so)
==1421==    by 0x4E92D3B: puts (in /lib/libc-2.14.1.so)
==1421==    by …
Run Code Online (Sandbox Code Playgroud)

c printf valgrind

6
推荐指数
1
解决办法
3834
查看次数

默认分配器是否归零int?

使用STL容器时,我不确定默认分配器分配的int是否已归零.以下代码表示问题的"是":

#include <map>
#include <iostream>

int main() {
  using namespace std;
  map<int, int> m;
  cout << m[1234] << endl;
}
Run Code Online (Sandbox Code Playgroud)

由于没有文件证实这一点,我不敢把它视为理所当然.

c++ stl allocator

5
推荐指数
2
解决办法
314
查看次数

如何使WPF ListView处于水平状态,并且将包含的图像拉伸到合适的高度?

我想要一个在水平方向上显示带有标签的图像的画廊ListView

每个列表项仅是带有标签的图像:

<DataTemplate x:Key="ImageItemTemplate">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="4*" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Image Grid.Row="0" Source="{Binding Image}" Stretch="UniformToFill" />
        <Label Grid.Row="1" Content="{Binding Title}" />
    </Grid>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)

为了制作ListView水平线,我将替换ListView.ItemsPanel为水平线StackPanel

<ListView.ItemsPanel>
    <ItemsPanelTemplate>
        <StackPanel Orientation="Horizontal" />
    </ItemsPanelTemplate>
</ListView.ItemsPanel>
Run Code Online (Sandbox Code Playgroud)

现在我得到这样的东西:

初始状态

但是我希望每个图像都可以拉伸以占据整个高度ListView(减去标签的足够高度),同时保持宽高比,所以我替换了ListView.ItemContainerStyle

<ListView.ItemContainerStyle>
    <Style TargetType="ListViewItem">
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="VerticalContentAlignment" Value="Stretch" />
    </Style>
</ListView.ItemContainerStyle>
Run Code Online (Sandbox Code Playgroud)

但是我不知道为什么每个项目的宽度都不会被拉伸而是被切割:

拉伸状态

请帮忙,谢谢!

编辑:

整个xaml如下所示:

<UserControl x:Class="Test.ImageGalleryControl"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        mc:Ignorable="d">
    <UserControl.Resources>
        <DataTemplate x:Key="ImageItemTemplate">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="4*" /> …
Run Code Online (Sandbox Code Playgroud)

c# wpf listview

1
推荐指数
1
解决办法
2366
查看次数